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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!