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', ''))
echo "Could not rename file";
else echo "File successfully renamed to 'testfile2.txt'";

Deleting a File

<?php // deletefile.php
if (!unlink('')) echo "Could not delete file";
else echo "File '' 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");
echo "File 'testfile.txt' successfully updated";

You may also like...