laravel 5 ->getRealPath() doenst show correct value

后端 未结 2 1702
生来不讨喜
生来不讨喜 2021-01-18 12:05

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 upl

相关标签:
2条回答
  • 2021-01-18 12:26

    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.

    0 讨论(0)
  • 2021-01-18 12:28

    Simply use this

    $_SERVER['DOCUMENT_ROOT']."/path/to/directory"
    
    0 讨论(0)
提交回复
热议问题