In order to Copy a file from one directory to another using PHP we can make use of copy() function,
bool copy ( string $srcLocation , string $dest [, resource $context ] )
The first parameter to copy function is the source location of the file, second parameter is the destination location.
Note : the third parameter is an $context is an optional parameter if you are passing it, it has to be a valid context resource created with stream_context_create() function,
Lets have a look at an example,
<?php
$srcFileName = 'fileA.php';
$copyFileName = 'fileACopy.php';
if (!copy($srcFileName, $copyFileName)) {
echo "Error occurred while copying file";
}
?>
Note : If the destination file already exists then the contents of the file will be overwritten.
copy() error: Permission denied : If you are getting such kind of error while trying to execute the copy function that make sure that you have provided the complete path with file Name for both the source and the destination folder. If you only provide the path for the destination folder you will get the error!!.
- Upload Pdf file using PHP Script
- 403 forbidden error for Image
- Installing vue.js in Laravel 8
- Copy file from one directory to other in Php
- Remove URL Forward Slash Before Single or Double quotes in php.ini
- PHP Script to Upload Images to Server
- PHP Base64 encoding decoding a variable
- Upload docx file using PHP script
- Delete file using PHP code : unlink()
- PHP 301 Redirect Permanently
- PHP Fatal error : Call to a member function bind_param() on a non-object
- Call PHP function on Button click using jquery ajax
- PHP header location function not called
- Failed to load resource: net::ERR_CACHE_MISS PHP
- PHP Code for sending Emails
- How to destroy PHP session()
- PHP drag and drop file upload tutorial using dropzone.js
- PHP Warning: Cannot modify header information - headers already sent
- How to display Toast in a thread : Android - Android
- Change CKEditor Table Properties default width - CKEditor
- Mac OS X Stuck During Booting Gray Screen Logo and Spinner - Mac-OS-X
- Find Difference of two numbers - C-Program
- Share Multiple Images in WhatsApp using Android Intent - WhatsApp
- Instant Run requires Tools | Android | Enable ADB integration to be enabled - Android-Studio
- Setting up Cloud feature with Notepad++ - NotepadPlusPlus
- W3 : character data is not allowed here html validation error - Html
- List of 60 useful FTP Client Commands to access server - FTP
- Write javaScript code in Swedish using FikaScript - JavaScript
- Android Installation error: INSTALL_FAILED_OLDER_SDK on Device - Android
- Programmatically Send an Email from Android App using Intent - Android
- jQuery : Move to top of the page - jQuery
- PHP Code for sending Emails - PHP
- Error:The SDK Build Tools revision (XX.X.X) is too low for project. Minimum required is XX.X.X - Android