PHP/File Directory/copy
Содержание
Copying a file
<source lang="html4strict">
<?php $old = "/tmp/yesterday.txt"; $new = "/tmp/today.txt"; copy($old,$new) or die("couldn"t copy $old to $new: $php_errormsg"); ?>
</source>
Copying files
<source lang="html4strict">
<?php
$source = "C:\\Apache\\logs\\error.log"; $dest = "C:\\error.bak"; if( copy( $source, $dest ) ) { $msg = "Copied $source
to $dest"; } else { $msg = "Unable to copy $source"; }
?> <html>
<head> <title>Copying files</title> <head> <body> <?php echo($msg); ?> </body>
</html>
</source>
Copying Files with copy( )
<source lang="html4strict">
<?
$filename = "data.txt"; $filename2 = $filename . ".old"; $result = copy($filename, $filename2); if ($result) { print "$filename has been copied to $filename2.\n"; } else { print "Error: couldn"t copy $filename to $filename2!\n"; }
?>
</source>
Make a copy of a file: copy() function.
<source lang="html4strict">
Its syntax is: int copy (string source, string destination) <?
$data_file = "data.txt"; copy($data_file, $data_file."bak") or die("Could not copy $data_file");
?>
</source>
Using the copy() Function
<source lang="html4strict">
<?php
function move($source, $dest) { if(!copy($source, $dest)) return false; if(!unlink($source)) return false; return true; } if(!move("data.txt", "/tmp/tmpdir/newfile.txt")) { echo "Error! Couldn"t move the file!
"; }
?>
</source>