compiled Posted November 21, 2008 Share Posted November 21, 2008 Hi. I upload every day a file on my web site using this script: $uploadfile = $uploaddir . basename($_FILES['nume_fis']['name']); if (move_uploaded_file($_FILES['nume_fis']['tmp_name'], $uploadfile)) {echo "File is valid, and was successfully uploaded.\n";} else { } The problem with the script is that it overwrites the file uploaded one day before. How can I do to merge the content of all uploaded files in a single file, so at the end of the week I can see all data that I have uploaded? Note: the file that I upload in not TXT but binary. I am beginner in PHP Thanks Link to comment https://forums.phpfreaks.com/topic/133575-script-to-upload-files-and-merge-their-content/ Share on other sites More sharing options...
trq Posted November 21, 2008 Share Posted November 21, 2008 Use fread to read the old file and new file into a variable, concatenate the variables together, then use fwrite to write them to a single file. Link to comment https://forums.phpfreaks.com/topic/133575-script-to-upload-files-and-merge-their-content/#findComment-694810 Share on other sites More sharing options...
compiled Posted November 21, 2008 Author Share Posted November 21, 2008 Thanks for the answer. That was may original idea, the problem is that the actual script (see above) already overwrite the existing file. So, I get no chance to concatenate them. Actually, I think my question should be: How to make the actual script not to overwrite the existent file? Link to comment https://forums.phpfreaks.com/topic/133575-script-to-upload-files-and-merge-their-content/#findComment-695302 Share on other sites More sharing options...
compiled Posted November 21, 2008 Author Share Posted November 21, 2008 I have found a solution: $newfile = $_FILES['nume_fis']['tmp_name']; $uploadfile = $uploaddir . basename($_FILES['nume_fis']['name']); if( is_readable($newfile) && is_readable($uploadfile) ) { //If the old file exists and is readable $result = file_put_contents($uploadfile, file_get_contents($uploadfile) . file_get_contents($newfile) ); //Appending new data and writing to file } else { $result = move_uploaded_file($newfile, $uploadfile); } if($result !== false) { echo "File is valid, and was successfully uploaded.\n"; } but there is a problem. The script above inserts an ENTER between records when it appends the files, breaking my binary format. Any ideas how to get rid of this. PS: Also, somebody suggested to use FILE_APPEND flag. Link to comment https://forums.phpfreaks.com/topic/133575-script-to-upload-files-and-merge-their-content/#findComment-695564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.