【问题标题】:Laravel File Upload with new name使用新名称上传 Laravel 文件
【发布时间】:2018-05-14 06:37:18
【问题描述】:

我有以下代码:

$randomNameCV = substr(md5(uniqid(rand())), 0, 10).date('YmdHi').".pdf";

$storeCV =  $request->cv->store('storage/cvs','public');

这允许我上传文件,但是当我使用这些方法指定文件名时无法上传:

$storeCV = $request->cv->storeAs(
    'storage/cvs', $randomNameCV
);

$storeCV = Storage::putFileAs(
    'storage/cvs', $request->file('cv'), $randomNameCV, 'public'
);

Documenation

【问题讨论】:

    标签: php laravel file file-upload


    【解决方案1】:

    像这样 - 记住扩展:

    Storage::putFileAs('photos', new File('/path/to/photo'), 'photo.jpg');
    

    【讨论】:

      【解决方案2】:

      这里的“头像”是表单的字段名——

      // name of the file
      $randomNameCV = substr(md5(uniqid(rand())), 0, 10).date('YmdHi').".pdf";
      
      // path and file name -- here public is folder name and randomNamecv is file
      
      $path = 'public/'.$randomNameCV;
      $request->file('avatar')->store($path);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-02-14
        • 1970-01-01
        • 1970-01-01
        • 2017-04-14
        • 1970-01-01
        • 2013-12-15
        • 1970-01-01
        相关资源
        最近更新 更多