Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 5 ->getRealPath() doenst show correct value

On my local development I use the code shown below, which works perfect,

but when I uploaded the site to my shared hosting everything worked fine except my file upload. I already determined that the problem is involving ->getRealPath(), when I dd(); that I get this path: /data/sites/web/christophvhbe/tmp

Which doesn't exist on my hosting. But I found where the temporary images are stored on my hosting, which is in the tmp/ located here: http://gyazo.com/e0199718324119109a4ff66321414e12.

How can I change the ->getRealPath() value to the correct value?

$fileName = time() . '-' . $request->file('foto')->getClientOriginalName();
$product->foto = $fileName;
$product->save();

$imagePath = '/images/producten/'. $fileName;

$image = Image::make($request->file('foto')->getRealPath())->fit(300)->save($imagePath);

I'm using the Image/intervention package to upload and store images.

like image 401
Christophvh Avatar asked Jun 22 '15 00:06

Christophvh


People also ask

Where is storage path Laravel?

Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.

What is public path in Laravel?

This is a typical Laravel folder structure, with the default public folder : / /app /bootstrap /config /database /public /index.php /resources /routes /storage. This is specially useful when you try to deploy or publish your application in a standard web server.

How can I upload my file name in Laravel?

$request->file->getClientOriginalName();


Video Answer


1 Answers

Chances are your account's root is /data/sites/web/christophvhbe, and that getRealPath is entirely accurate (what you see in FTP is likely chrooted). As a result, your $imagePath is actually the problem.

$imagePath = '/data/sites/web/christophvhbe/images/producten/'. $fileName;

Or, better yet, use Laravel's base_path and/or public_path helpers so if you ever change hosting it keeps working if the paths change:

$imagePath = public_path() . '/images/producten/' . $fileName;

If you consult your error logs, I'll bet you find permissions errors trying to create a file in the server's /images directory, which on shared hosting you definitely won't be able to create or access.

like image 130
ceejayoz Avatar answered Oct 07 '22 13:10

ceejayoz