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.
$filename = 'filename.txt';
$desturl = '';
$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)";

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

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


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

Share this

Related Posts