1

I'm having trouble with uploading an image to my local server. I test it in POSTMAN.

I doubt it is my $path that causes the error.

pm

My upload.php

header('Content-type : bitmap; charset=utf-8');

if(isset($_POST["encoded_string"])){

    $encoded_string = $_POST["encoded_string"];
    $image_name = $_POST["image_name"];

    $decoded_string = base64_decode($encoded_string);

    $path = 'C:/Users/Luffy/Documents/XAMPP/htdocs/images/'.$image_name;

    $file = fopen($path, 'wb');

    $is_written = fwrite($file, $decoded_string);
    fclose($file);

    if($is_written > 0) {

        $connection = mysqli_connect('localhost', 'root', 'password','photos');
        $query = "INSERT INTO photos(name,pathFile) values('$image_name','$path');";

        $result = mysqli_query($connection, $query) ;

        if($result){
            echo "success";
        }else{
            echo "failed";
        }

        mysqli_close($connection);
    }
}

How do I exactly map folders in Xammp? I tried getting $_SERVER['DOCUMENT_ROOT'] but it doesn't working.

Sherif
  • 11,786
  • 3
  • 32
  • 57
RoCkDevstack
  • 3,517
  • 7
  • 34
  • 56
  • You don't have an error yet. You just have code that doesn't do what you expected it to do. If `$result` is `false` then you need to check `mysqli_error($connection)` to get the actual error returned from your dbms and start there. – Sherif Aug 31 '16 at 09:20
  • I'm adding `mysqli_error($connection)` at the end of the statement of $result. – RoCkDevstack Aug 31 '16 at 09:26
  • It gives me this - `fopen(images/hehe.png): failed to open stream: No such file or directory in C: \...\....\. ` – RoCkDevstack Aug 31 '16 at 09:28
  • Read this Anwser: http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory have you permission to the folder =? – Provie9 Aug 31 '16 at 09:28
  • I didn't create a dir programmatically, I created a sample folder for placing images intentionally. Does it need file permission - to write? Thanks for the link I'm looking to it also. – RoCkDevstack Aug 31 '16 at 09:31
  • It's working now, but `POSTMAN` will give me this error - `Unknown column 'name' in 'field list'` - but my icon is uploaded in the folder - images. Can I ask a question? Is this how I locate `path` / `map` my folder ? I assume that since I'm inside `XAMMP` - it will look for it's directory inside `htdocs` . – RoCkDevstack Aug 31 '16 at 09:49

0 Answers0