mzhou88 Posted March 5, 2007 Share Posted March 5, 2007 this is how i splited the uploaded file: $data = chunk_split(base64_encode(file_get_contents($file)), 9560, "\r\n\r\n\r\nxcowend"); $arrData = explode("\r\n\r\n\r\nxcowend", $data); - then i counted how manie lines of $arrData is has -1 this is how i joined the splitted parts: $file = file('test.txt'); $count = count($file)-1; //echo $count; $i = 0; $file = ''; while($i < $count) { $i = $i+1; $file .= file_get_contents($i); } $filex = base64_decode($file); $han = fopen('testx.doc','w'); fwrite($han,$filex); fclose($han); test.txt has recorded the number of parts the file was splitted into. but when the file came out, it was 8kb smaller! and when i open it, it cant be read. weird? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 Replace the entire while loop with this: $file = file_get_contents('test.txt'); The while loop was actually putting nonsense into $file, as you were calling file_get_contents() with $i instead of a filename. Quote Link to comment Share on other sites More sharing options...
mzhou88 Posted March 5, 2007 Author Share Posted March 5, 2007 sorry i guess i should have expanded on my first post. currently heres the splitted files in the directory (no extentions): 01 02 03 then in test.txt, it is like this: 01 02 03 but i just count the lines of in test.txt to check how many parts the file was split up to. then in the loop, i actually get the contents all into the string $file. if i dunt use loops i dunt know how i could have gotten all the files together. //edit and if the loop was putting more data into the string, wouldnt the filesize be bigger instead of smaller? thanks! =p Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 Ok I get it I think a good way to debug will be to store the original base64 encoded string, and the reconstructed string, and print each of them out. Looking at them you should be able to see what's going wrong. IE, compare $filex in the bottom code to the output of base64_encode(), and see what's changed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.