Home Tutorial Php Phpfiles Copy file in php, How to copy file in php, PHP copy file

 
 

Copy file in php, How to copy file in php, PHP copy file
Posted on: September 21, 2009 at 12:00 AM
In this example code I will show you how you can copy files in PHP program.

Learn How to copy file in php. The PHP copy file example explained here copies the content of one file (aa.tx) into another file (bb.txt). 

In the following example we will show you how to use of copy() function in php. The copy function in PHP is used to copy the content of one file into another file.

Syntax of Copy file in PHP

boolean copy ( string $source_file, string $target_file )

The copy function copies the content of source_file into target_file. It returns the true or false Value.

Copy file example code

<?php

$file1=fopen("aa.txt","w");//Open the file into write mode

$file2=fopen("bb.txt","w"); 

fwrite($file1,"this is roseindia",30);

echo copy("aa.txt","bb.txt");//Copy the content of aa.txt into bb.txt

echo"<br>";

echo fread($file2,30);//Display the content of bb.txt

?>

Output

1
this is roseindia

 

Related Tags for Copy file in php, How to copy file in php, PHP copy file:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.