Now, let is take a look at the php copy file article from one folder to another. you will read a copy of the image from one folder to another in php. I can easily explain step by step copying a file from one folder to another folder in php. step by step explain how to copy a file from one folder to another in php. Let's start with an example of a php copy file.

If you need to copy a file from one folder to another using the php code then we can use the "copy ()" php function. php provides a copy function to copy your file from one location to another.

Here I will give you a simple example with syntax on how it works to copy a file from one folder to another folder in php.

Let’s take a look at the below 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 require to give file path that you want to copy.

$destination: you require 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!";  
} 
  
?>