1

I'm developing an Restful Services for Android application and i'm trying to upload image to localhost from application, but keep getting an error on finding the location where an image was stored.

I'm storing data in DB successfully, but not storing image in folder on localhost.

This is how i'm locating folder:

$path = "uploads/$id.png";

$actualpath = "http://localhost:8081/joke_bro/$path";

// creating new joke
$joke_id = $db->createJoke($user_id, $joke_text, $user_name, $actualpath, $image_name);

if ($joke_id != NULL) {
    $response["error"] = false;
    $response["message"] = "Joke created successfully";
    file_put_contents($path, base64_decode($image));
    echoResponse(201, $response);
} else {
    $response["error"] = true;
    $response["message"] = "Failed to create joke. Please try again";
    echoResponse(200, $response);
}   

actualpath is urlPathLink that i'm storing in DB, but i need now to store also image to that folder using function file_put_contents. However i'm getting some error with path location of that folder.

Here is the error:

<strong>Message:</strong> file_put_contents(uploads/35.png): failed to open stream: No such file or directory

Here is the path from where i'm executing this code:

E:\xampp\htdocs\joke_bro\v1

And here i should store images:

E:\xampp\htdocs\joke_bro\uploads
Dusan Dimitrijevic
  • 3,169
  • 6
  • 22
  • 46
  • 1
    how about using the full path, not a relative one –  Apr 26 '16 at 03:01
  • 1
    As you mentioned, your code is not running from the root so u need to use the path like this: `$path = "../uploads/$id.png";` Or you can use the absolute path. And make sure uploads directory has the proper permissions...Thanks – Usman Pervaiz Apr 26 '16 at 05:05
  • Solved it. Thank you guys.. – Dusan Dimitrijevic Apr 26 '16 at 10:07
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Apr 26 '16 at 12:19

0 Answers0