Home > Backend Development > PHP Tutorial > PHP implements file copy

PHP implements file copy

WBOY
Release: 2016-07-29 09:11:17
Original
1141 people have browsed it

Use fread fwrite fclose

1.

$inputDir="D:/ccc.txt";
$outputDir="D:/ddd.txt";
//是否存在输出目录
if(!file_exists($outputDir)){
$dirs=fopen($outputDir,'w');
fclose($dirs);
}
$handle=fopen($inputDir,'r');
$c
fclose($handle);
$outResouse=fopen($outputDir,'w');
fwrite($outResouse,$content);
fclose($outResouse);
Copy after login
2.
<pre name="code" class="php">$inputDir="D:/ccc.txt";
$outputDir="D:/ddd.txt";
Copy after login
Copy after login
$c
$handle2=fopen($inputDir,'r');
$outResouse2=fopen($outputDir,'w');
while (!feof($handle2)) {
  $content2 .= fread($handle2, 10);
}
fwrite($outResouse2,$content2);
fclose($handle2);
fclose($outResouse2);
Copy after login
3.
<pre name="code" class="php">$inputDir="D:/ccc.txt";
$outputDir="D:/ddd.txt";
Copy after login
Copy after login
$c
$handle3=fopen($inputDir,'r');
$outResouse3=fopen($outputDir,'w');
$i=0;
while (!feof($handle3)) {
  $content3 = fread($handle3, 10);
fseek($outResouse3,$i*10);
fwrite($outResouse3,$content3);
$i++;
}
fclose($handle3);
fclose($outResouse3);
Copy after login

4.

$c
$handle4=fopen($inputDir,'r');
$outResouse4=fopen($outputDir,'w');
while(($c
fwrite($outResouse4,$content4,10);
}
fclose($handle4);
fclose($outResouse4);
Copy after login

4 methods are similar! ! !

The above has introduced the implementation of file copying in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template