Copying, moving, deleting and updating php files
Copying files
<?php // copyfile.php copy('testfile.txt', 'testfile2.txt') or die("Could not copy file"); echo "File successfully copied to 'testfile2.txt'"; ?>
Moving a File
<?php // movefile.php if (!rename('testfile2.txt', 'testfile2.new')) echo "Could not rename file"; else echo "File successfully renamed to 'testfile2.txt'"; ?>
Deleting a File
<?php // deletefile.php if (!unlink('testfile2.new')) echo "Could not delete file"; else echo "File 'testfile2.new' successfully deleted"; ?>
Updating a File
<?php // update.php $fh = fopen("testfile.txt", 'r+') or die("Failed to open file"); $text = fgets($fh); fseek($fh, 0, SEEK_END); fwrite($fh, "$text") or die("Could not write to file"); fclose($fh); echo "File 'testfile.txt' successfully updated"; ?>