Search code examples
phplaravellaravel-5file-copying

How to copy files in laravel 5 controller


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/'));

Solution

  • 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'));