473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

i need to write content of one text file into another text file.

kamill
71
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]
Jan 9 '07 #1
2 2558
ronverdonk
4,258 Expert 4TB
Are you UPloading the file to the server before you copy it ? If not, and it is just a local affair, why do you use the $_FILES array? And what do you expect to find in it?

If the copy is local, it is just a matter of passing the 2 file names to the copy routine via the normal $_POST and use these in your copy part of the script.

Ronald :cool:
Jan 9 '07 #2
kamill
71
Thanks Ronalds... i have got the point.
Jan 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jajoo | last post by:
Hi everyone, I am trying to send files with multipart/form-date. Everything is ok with the send. But when I am receiving the files I should specify a directory where the files to be saved. The...
6
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I...
1
by: capb | last post by:
Hello, This is my first post, and any help would be greatly appreciated. I create online memorials which contain guestbooks which have been the subject of computer generated spam. I have been able...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
16
by: btopenworld | last post by:
Hi - question from a relative asp novice I have written to text files in the past, but always appending new data to the end of the text file. I now want to add the new data to the beginning of...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
12
by: lalou89 | last post by:
Develop a simple text editor program. The program will show the user a menu of choices and will act according to his choice. Use functional decomposition to break the system into small functions that...
3
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.