2

When uploading images, getRealPath() always returns false:

$image_file = $request->file('image_file');
$image_file->getRealPath(); // ---> FALSE

Here is the result of dd($image_file);:

enter image description here

Also, when I try to use it with Image Intervention:

        $image_file = $request->file('image_file');

        Image::make($image_file->getRealPath())->.....

I am getting the following error:

NotReadableException in AbstractDecoder.php line 323: Image source not readable

Obviously because getRealPath() returns false... Someone has already asked about this problem: getRealPath returning false (Image Intervention and Laravel 5.1) ... but there is no solution.

Do you know why is this happening, how can I fix this?

Community
  • 1
  • 1
PeraMika
  • 3,211
  • 7
  • 36
  • 57
  • is your picture size is big ? see this answer if it helps http://stackoverflow.com/questions/25929197/laravel-inputhasfileimage-returns-false-even-if-a-file-is-uploaded?rq=1 – Vikash Jan 27 '17 at 18:27
  • @Vikash No, the image size is 16kb, so no, that is not a problem. – PeraMika Jan 27 '17 at 18:38
  • @PeraMika Have you tried (like the guy on the post you linked) to avoid using `getRealPath()` method and use `public_path()` method instead? That should resolve your problem. – Mihailo Jan 27 '17 at 18:41
  • @Mihailo Yes, like this: `$request->file('image_file')->public_path()` and I am getting **Method public_path does not exist.**. – PeraMika Jan 27 '17 at 18:44
  • You can not **"chain"**. Try `public_path($request->file('image_file')->getClientOriginalName())` instead. – Mihailo Jan 27 '17 at 18:51
  • you can check this issue https://github.com/Intervention/image/issues/26 – Vikash Jan 27 '17 at 18:52
  • @Mihailo No it doesn't work... The `public_path` function returns the fully qualified path to the public directory, and I need a getRealPath() which gets absolute path to TEMP file that was just uploaded (located in C:\Windows\**Temp**... not in the project's public directory). – PeraMika Jan 27 '17 at 19:08

2 Answers2

2

The problem was in php.ini - incorrect upload dir.

PeraMika
  • 3,211
  • 7
  • 36
  • 57
  • can you please share the error that was found in php.ini file of yours. i am facing same problem i don't see any problem with my ini file also my temp upload path is C:\Windows\Temp but still not getting path by ->getRealpath() function its returning false – Zeeshan Awan Nov 11 '21 at 17:56
0

I got the same problem with the getRealPath(). It returns false when I dd(). Try using $request->getPathname() instead.

Dharman
  • 26,923
  • 21
  • 73
  • 125