How to copy a file from one directory to another using PHP ? Last Updated : 25 Sep, 2019 Comments Improve Suggest changes Like Article Like Report The copy() function in PHP is used to copy a file from source to target or destination directory. It makes a copy of the source file to the destination file and if the destination file already exists, it gets overwritten. The copy() function returns true on success and false on failure. Syntax: bool copy( string $source, string $destination, resource $context ) Parameters: This function uses three parameters source, destination and context which are listed below: $source: It specifies the path of the source file. $destination: It specifies the path of the destination file or folder. $context: It specifies the context resource created with stream_context_create() function. It is optional parameter. Return: It returns a boolean value, either true (on success) or false (on failure). Examples: Input : $source = 'Source_file_location' $destination = 'Destination_file_location' copy( $source, $destination ) Output: true PHP <?php // Copy the file from /user/desktop/geek.txt // to user/Downloads/geeksforgeeks.txt' // directory // Store the path of source file $source = '/user/Desktop/geek.txt'; // Store the path of destination file $destination = 'user/Downloads/geeksforgeeks.txt'; // Copy the file from /user/desktop/geek.txt // to user/Downloads/geeksforgeeks.txt' // directory if( !copy($source, $destination) ) { echo "File can't be copied! \n"; } else { echo "File has been copied! \n"; } ?> Output: File has been copied! Reference: https://www.php.net/manual/en/function.copy.php Comment More infoAdvertise with us Next Article How to copy a file from one directory to another using PHP ? J jaideep45 Follow Improve Article Tags : Technical Scripter Web Technologies PHP PHP Programs Technical Scripter 2019 +1 More Similar Reads Copy the entire contents of a directory to another directory in PHP Given a directory and the task is to copy the content of the directory to another directory using PHP functions. There are many functions used to copy the content of one directory to another. Used Functions: copy() Function: The copy() function is used to make a copy of a specified file. It makes a 3 min read How to move a file into a different folder on the server using PHP? The move_uploaded_file() function and rename() function is used to move a file into a different folder on the server. In this case, we have a file already uploaded in the temp directory of server from where the new directory is assigned by the method. The file temp is fully moved to a new location. 3 min read How to post data using file_get_contents in PHP ? The file_get_contents() function in PHP is used to read the contents of a file and make HTTP requests using GET and get HTTP responses using POST methods. The HTTP POST request can be made using the $context parameter of the file_get_contents() function, which posts the specified data to the URL spe 3 min read How to delete a file using PHP ? To delete a file by using PHP is very easy. Deleting a file means completely erase a file from a directory so that the file is no longer exist. PHP has an unlink() function that allows to delete a file. The PHP unlink() function takes two parameters $filename and $context. Syntax: unlink( $filename, 2 min read How to Zip a directory in PHP? ZIP is an archive file format that supports lossless data compression. A ZIP file may contain one or more files or directories that may have been compressed. The PHP ZipArchive class can be used to zipping and unzipping. It might be need to install the class if it is not present. Installation for Li 2 min read Like