I want copy file to folder in laravel. when I copy file show me this error
The second argument to copy() function cannot be a directory
My code:
$success = \File::copy(base_path('test.text'),base_path('public/'));
I want copy file to folder in laravel. when I copy file show me this error
The second argument to copy() function cannot be a directory
My code:
$success = \File::copy(base_path('test.text'),base_path('public/'));
The error says what it means. If you read the docs on the copy() function it states you must copy from a file to a new file. Eg copying content from a .txt file to another.txt file.
So just add test.text after the public part and it will create a new file or overwrite an existing one.
$success = \File::copy(base_path('test.text'),base_path('public/test.text'));
You can use the public_path()
function to get the path to the public/
folder you can copy that file like this
$destinationPath=public_path()."/UploadFolderName/FileName.ext";
$success = \File::copy(base_path('test.text'),$destinationPath);
now the question
is where is your source file
? if it is already in the public folder
than you get the full path of that file like this.
$sourceFilePath=public_path()."/SomeFolderName/FileName";
$destinationPath=public_path()."//UploadFolderName/FileName.ext";
$success = \File::copy($sourceFilePath,$destinationPath);
Happy Coding!!!
EDIT
public_path()
is laravel
inbuilt function that give the full path
of the public
folder. for more information read here: https://laravel.com/docs/5.2/helpers#method-public-path
© 2022 - 2024 — McMap. All rights reserved.