what is preventing base64_decode from working for large files/images <p>I have implemented three php scripts, two of which proposed on stackoverflow, to resolve an issue where base64_decode of larger images didn't work. At this point I have given up on the php script and am just wondering what server upgrade might be necessary to get it to work. All three work on one server with any resolution, but on another server the maximum resolution obtained is around 1680 x 800 (file size around 140 kb). Beyond this, it fails and it outputs an empty image (filesize 0 kb). The data is posted from a Flash app. the only difference I can see between the two servers is the php memory limit (256 MB vs 128 MB). Could this be it? Thanks for any suggestions!</p> <p>The php scripts tried are copied below:</p> <p>version 1:</p> <pre><code>$png = base64_decode($_POST['imagedata']); header('Content-Type: image/png'); header("Content-Disposition: attachment; filename=".$_GET['name']); echo $png; </code></pre> <p>version 2:</p> <pre><code>$encoded = $_POST['imagedata']; $decoded = ""; for ($i=0; $i &lt; ceil(strlen($encoded)/256); $i++) $decoded = $decoded . base64_decode(substr($encoded,$i*256,256)); header('Connection: Keep-alive'); header('Content-Type: image/png'); header("Content-Disposition: attachment; filename=".$_GET['name']); echo $decoded; </code></pre> <p>version 3:</p> <pre><code>$data = $_POST['imagedata']; $target = 'img_'.date('Y-m-d-H-s').'.png'; $whandle = fopen($target,'w'); stream_filter_append($whandle, 'convert.base64-decode',STREAM_FILTER_WRITE); fwrite($whandle,$data); fclose($whandle); header("Content-Length: " . filesize($target)); header("Content-Disposition: attachment; filename=" . basename($target)); readfile($target); unlink($target); </code></pre>