note 46505 added to function.base64-decode
| From: | webmaster at technotoad dot no5pam dot com | Date: | Wed, 13 Oct 2004 15:49:59 +0000 |
| Subject: | note 46505 added to function.base64-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78498@lists.php.net to get a copy of this message | ||
I had the task of base64 decoding a large (>1Mb) file, and PHP fell over on my server when trying
to base64 decode such a lot of data in one go.
I found that you could cut the file into smaller chunks, decode them individually and recombine to
form a decoded file. This worked as long as the size of each chunk was divisible by 4, as base64
encodes in 4 character groups.
<?php
#open input and output files
$infile = fopen($input_file_name, "r");
$outfile = fopen($output_file_name, "w");
#step through input file
while (!feof($infile)) {
#get a 1024 byte (256*4) piece of infile
$line = fread($infile, 1024);
#base64 decode it and write it to outfile
fwrite ($outfile,base64_decode($line));
}
#close the files
fclose ($infile);
fclose ($outfile);
?>
----
Manual Page -- http://www.php.net/manual/en/function.base64-decode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46505
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46505&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46505&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46505&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46505&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46505&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46505&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46505&report=yes
Search -- http://master.php.net/manage/user-notes.php