Our PHP script is hosted on Linux based Apache Server. I have a form with one textarea and a submit button. This textarea contains a very long base64 string of 284312 characters.
When I submit this form it takes too much time. It is still processing after a very long time. It is working for small base64 string and images are posted successfully but it is not working with large size images base64 string.
I am using following code on server side to get this base64 image:
$ifp = fopen( "images/myimage.png", "wb" );
$status = fwrite( $ifp, base64_decode( str_replace(' ', '+', $_REQUEST['image'] ) ) );
fclose( $ifp );
Is there any solution for this? Should I change anything in my PHP or Apache configuration ?
Try it without $_REQUEST, my complete script first, here is the code which works fine for me, if it does not work for you, then provide complete info about PHP/webserver/machine (os, cpu..): But I think it is something about passing chars from your textarea to the code, I did not get it well how you do it, but testing script below gives us answers :)
<?php
$time_start = microtime(true);
$imagedata = file_get_contents('Cat2.jpg'); //5616998 bytes
$base64 = base64_encode($imagedata);
//echo strlen($base64); //7489332 characters
$ifp = fopen('myimage.png', 'wb');
$status = fwrite($ifp, base64_decode(str_replace(' ', '+', $base64)));
fclose($ifp);
echo 'Total execution time in seconds: ' . (microtime(true) - $time_start); //0.098897218704224 seconds
?>
More posted in comments before.