Home  >  Article  >  Backend Development  >  PHP implements file copy

PHP implements file copy

WBOY
WBOYOriginal
2016-07-29 09:11:171125browse

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);
2.
<pre name="code" class="php">$inputDir="D:/ccc.txt";
$outputDir="D:/ddd.txt";
$c
$handle2=fopen($inputDir,'r');
$outResouse2=fopen($outputDir,'w');
while (!feof($handle2)) {
  $content2 .= fread($handle2, 10);
}
fwrite($outResouse2,$content2);
fclose($handle2);
fclose($outResouse2);
3.
<pre name="code" class="php">$inputDir="D:/ccc.txt";
$outputDir="D:/ddd.txt";
$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);

4.

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

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.

Statement:
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