i need to write content of one text file into another text file.
My code is working ,if i choose both files from same directory where my program reside..BUT,its not working if i select files from out of that directory(where my application reside).
how can i overcome to it.
my code is this..
Form to select two files
[HTML]<form method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="post" value="posted" >
Select frist file(to read)<input type="file" name="txt1">
Select second file(to write)<input type="file" name="txt2">
<input type="submit" value="Submit">
</form>
[/HTML]
[PHP]if(isset($_POST['post'])=="posted")
{
echo $txt1=$_FILES['txt1']['name'];
echo $txt2=$_FILES['txt2']['name'];
// get contents of a file into a string
$filename = $txt1;
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
<?php
$filename2 = $txt2;
//$filename = $contents;
$somecontent = $contents;
// Let's make sure the file exists and is writable first.
if (is_writable($filename2)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle2 = fopen($filename2, 'a')) {
echo "Cannot open file ($filename2)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle2, $somecontent) === FALSE) {
echo "Cannot write to file ($filename2)";
exit;
}
?>
<Table align="center" border="1" bgcolor="#FFFFFF">
<TR><TD><?php
echo "Success, wrote ($somecontent) to file ($filename2)";
?></TD></TR></Table>
<?php
fclose($handle2);
} else {
echo "The file $filename is not writable";
}
}
?> [/PHP]