How to copy a file from one directory to another using PHP?

0 votes
I've got a file test.php in foo directory as well as bar. How can I replace bar/test.php with foo/test.php using PHP? I'm on Windows XP, a cross platform solution would be great but windows preferred.
Oct 1 in PHP by kartik
• 35,620 points
46 views

2 answers to this question.

0 votes

Hello @kartik,

You could use the copy() function :

// Will copy foo/test.php to bar/test.php
// overwritting it if necessary
copy('foo/test.php', 'bar/test.php');

Hope it helps!!

Thank You!!

answered Oct 1 by Niroj
• 77,360 points
0 votes

Simply,

$source = 'Source_file_location'
        $destination = 'Destination_file_location'
        copy( $source, $destination )
answered Oct 12 by anonymous
• 140 points

Related Questions In PHP

0 votes
1 answer

How to check if a file exists from a url using php?

Hello, You have to use CURL function does_url_exists($url) { ...READ MORE

answered Nov 3 in PHP by Niroj
• 77,360 points
75 views
0 votes
1 answer

How can one check to see if a remote file exists using PHP?

Hello @kartik, You can instruct curl to use ...READ MORE

answered Nov 10 in PHP by Niroj
• 77,360 points
26 views
0 votes
1 answer

How to delete all files from a folder using PHP?

Hello @kartik, Use this: $files = glob('path/to/temp/*'); // get ...READ MORE

answered Sep 13 in PHP by Niroj
• 77,360 points
47 views
0 votes
1 answer

How to create and download a csv file from php script?

Hello @kartik, You can use the built in fputcsv() for ...READ MORE

answered Oct 27 in PHP by Niroj
• 77,360 points
46 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 77,360 points
445 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5 in Java-Script by Niroj
• 77,360 points
690 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8 in PHP by Niroj
• 77,360 points
91 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8 in Node-js by Niroj
• 77,360 points
87 views
0 votes
1 answer

How to copy a file from one directory to another using PHP?

Hello @kartik, You could use the copy() function : // Will ...READ MORE

answered Sep 15 in PHP by Niroj
• 77,360 points
47 views
0 votes
1 answer

How to call function of one php file from another php file and pass parameters to it?

Hello @kartik, Include the first file into the ...READ MORE

answered Aug 27 in PHP by Niroj
• 77,360 points
342 views