Home Tutorial Php Examples copy() example


Share on Google+Share on Google+
copy() example
Posted on: July 30, 2009 at 12:00 AM
Here you will learn the example of copy() in PHP.

Copying a file in PHP

In this example, you will learn 'how to copy a file in PHP programming language?'

For copying a file, we use copy command from source to destination within PHP code tag like 

copy ($source,$destination);

Lets do it practically. 

First begin the PHP tag (<?php), define the source path and destination under $source and $destination respectively. 

Apply the conditional statement to print the output result.

$source = "C:\\wamp\\www\\projects\\public_html\\upload\\mytextfile.txt";
$destination = "C:\\wamp\\www\\projects\\public_html\\upload\\myfile.txt";

if(copy($source, $destination)) {
echo "File copied successfully.", "\n";
} else {
echo "The file not copied. Please try again.", "\n";


In the above example, if file be exists and copied successfully, the print will be "File copied successfully." otherwise the output will be "The file not copied. Please try again".


Related Tags for copy() example:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 30, 2009

Recommend the tutorial

Advertisements Advertisements