Jump to content

Upload using chunk_split & base64_encode


mzhou88

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/41187-upload-using-chunk_split-base64_encode/
Share on other sites

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.