dqd54099 2018-04-27 13:57
浏览 134
已采纳

如何将上传的文件移动到Laravel中public_html内的公共文件夹?

I have a laravel website up and running but I am facing the file uploading issue.I am using the move function to move my uploaded files to my public folder. It is working fine in my Xampp but as I uploaded the website to my server it is not working anymore because the public folder is now inside the public_html. Any help with that??

  • 写回答

1条回答 默认 最新

  • dongtang6718 2018-04-27 14:11
    关注

    Destination where you want to move you file

     $destinationPath = 'img';
    

    Image new name

    $imageName = 'img_' . rand(1000000, 9999999) . '.' . $request->file('file_name')->getClientOriginalExtension(); //$product->id . '.' .$request->file('file_name')->getClientOriginalExtension();
    

    Move file

    $request->file('file_name')->move($destinationPath, $imageName);
    

    File path

    $path = public_path() . '/' . $destinationPath . '/' . $imageName;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?