【问题标题】:Store file to s3 bucket using php Laravel使用 php Laravel 将文件存储到 s3 存储桶
【发布时间】:2020-05-05 12:33:23
【问题描述】:

请我想根据其目录将文件存储在 s3 中,但是当我执行此代码时,它会保存字符串“storage / ;;;”在文件上,而不是包含内容的 docx 上??

            $path = "storage/uploads/l42fZsuxHTWJhCCh1G9QZVqFVyyjPk8E0046sjAQ.docx";
            Storage::disk('s3')->put("fusiondoc/doc",$path,'public');

我还通过添加 Storage :: get 使用此代码进行了测试,但它不起作用??谢谢你

           $path = "storage/uploads/l42fZsuxHTWJhCCh1G9QZVqFVyyjPk8E0046sjAQ.docx";
            $content = Storage::get($path);
            $full_path  = Storage::disk('s3')->put("fusiondoc/doc",$content,'public');

【问题讨论】:

    标签: php laravel amazon-s3 minio


    【解决方案1】:

    第二个参数是内容而不是路径,所以像这样更新

    $path = "storage/uploads/l42fZsuxHTWJhCCh1G9QZVqFVyyjPk8E0046sjAQ.docx";
    Storage::disk('s3')->put("fusiondoc/doc/l42fZsuxHTWJhCCh1G9QZVqFVyyjPk8E0046sjAQ.docx",fopen($path),'public');
    

    评论更新

    $fileName = uniqid () . Str::afterLast($path,".");
    Storage::disk('s3')->put("fusiondoc/doc/" . $fileName,fopen($path),'public');
    

    【讨论】:

    • 非常感谢你,它可以工作,但是如果我想要这个而不是在 Storage::put 中写一个 name.docx 来保存文件,请为文件生成一个随机名称?
    猜你喜欢
    • 1970-01-01
    • 2017-11-23
    • 2020-10-10
    • 2019-08-07
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2021-02-07
    相关资源
    最近更新 更多