Storage::putFile()当我存储上传的文件时,我使用Laravel ,我喜欢它的自动唯一文件名以及它如何处理文件扩展名的便利。
现在,我想从远程服务器(file_get_contents($url))获取文件并像对待上载文件一样存储它,但是我在文档中找不到任何相等的方法。
在该方法的https://laravel.com/docs/5.5/filesystem#storing-files中put,您必须指定文件名。
$filename = uniqid().File::extension($file->getClientOriginalName());
//uniqid() is php function to generate uniqid but you can use time() etc.
$path = "Files/Images/"
Storage::disk('local')->put($path.$filename,file_get_contents($file));
Run Code Online (Sandbox Code Playgroud)
如果你有一个UploadedFile实例,你也可以使用$file->hashName()
https://laravel.com/api/5.5/Illuminate/Http/UploadedFile.html#method_hashName
https://github.com/laravel/framework/blob/5.5/src/Illuminate/Http/FileHelpers.php#L52
| 归档时间: |
|
| 查看次数: |
7408 次 |
| 最近记录: |