par*_*oid 3 php file-copying laravel laravel-5 laravel-5.2
我希望将文件复制到laravel中的文件夹.当我复制文件时告诉我这个错误
copy()函数的第二个参数不能是目录
我的代码:
$success = \File::copy(base_path('test.text'),base_path('public/'));
Run Code Online (Sandbox Code Playgroud)
Ben*_*wis 10
错误说明了它的含义.如果您阅读copy()函数上的文档,则表明您必须从文件复制到新文件.例如,将内容从.txt文件复制到another.txt文件.
因此,只需在公共部分之后添加test.text,它将创建一个新文件或覆盖现有文件.
$success = \File::copy(base_path('test.text'),base_path('public/test.text'));
Run Code Online (Sandbox Code Playgroud)
您可以使用该public_path()函数获取public/文件夹的路径,您可以像这样复制该文件
$destinationPath=public_path()."/UploadFolderName/FileName.ext";
$success = \File::copy(base_path('test.text'),$destinationPath);
Run Code Online (Sandbox Code Playgroud)
现在question你在哪里source file?如果已经存在,则public folder您将获得该文件的完整路径,如下所示。
$sourceFilePath=public_path()."/SomeFolderName/FileName";
$destinationPath=public_path()."//UploadFolderName/FileName.ext";
$success = \File::copy($sourceFilePath,$destinationPath);
Run Code Online (Sandbox Code Playgroud)
快乐编码!
编辑
public_path()是laravel内置功能,可提供完整path的public文件夹。有关更多信息,请参阅此处:https : //laravel.com/docs/5.2/helpers#method-public-path
| 归档时间: |
|
| 查看次数: |
14866 次 |
| 最近记录: |