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.
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.
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.
$request->file->getClientOriginalName();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With