PHP Copy File from One Folder to Another Example
Hello Dev,
Now, let's see article of php copy file from one folder to another. you'll learn copy image from one folder to another in php. i explained simply step by step copy a file from one folder to another folder in php. step by step explain how to copy file from one folder to another in php. Let's get started with php copy file example.
If you need to copy file from one folder to another using php code then we can use "copy()" function of php. php provide copy function to copy your file from one place to another.
So, here i will give you very simple example and syntax how it works to copy file from one folder to another in php.
Let's see bellow syntax and example that will help you.
Syntax:
bool copy( string $source, string $destination, resource $context )
You can see bellow parameter in details:
$source: you need to give file path that you want to copy.
$destination: you need to give file path for destination source.
$context: this is optional, It specifies the context resource created with stream_context_create() function.
Example:
<?php
/* Store the path of source file */
$filePath = 'images/test.jpeg';
/* Store the path of destination file */
$destinationFilePath = 'copyImages/test.jpeg';
/* Copy File from images to copyImages folder */
if( !copy($filePath, $destinationFilePath) ) {
echo "File can't be copied!";
}
else {
echo "File has been copied!";
}
?>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Create Directory If It Doesn't Exist Example
- How to Delete File from Public Folder / Storage Folder in Laravel?
- Laravel Copy File from One Folder to Another Example
- PHP - Getting Started PHPUnit Test Example
- How to Copy Text to Clipboard without Flash using JQuery?
- PHP Remove Duplicates from Multidimensional Array Example
- How to Get Size of Directory in MB Laravel?
- How to Get Folder Path from File Path in PHP?
- How to Send Mail in PHP Laravel?
- How to Convert Object into Array in PHP?
- How to Count Number of Files in Directory using PHP?
- How to Count Number of Files in a Directory in PHP?