Php Script To Read & Copy File

Php Script To Read & Copy File

Script to read and copy the contents of a text file to another file. Hope it works.
<?php
$filename = 'filename.txt';
$desturl = 'http://urltofile.com/path/filename.txt';
$content = file_get_contents("$desturl");
;

// Check to see if file is writable
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $content will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Successfully wrote the contents of <b>($newfile)</b> to <b>($filename)</b>";

fclose($handle);

} else {
echo "Error, $filename is not writable";
}
?>

Share this

Related Posts

There was an error in this gadget