I had changed an image to string using base64_encode() function.

In now want to convert this string back to an image for saving it into a folder.

Please help....


7 Years
Discussion Span
Last Post by jino

try this: string convert_uuencode ( the coded version of your pic/text )

I took from php.net manual. I hope that to be of any help!

update: my bed!!

Edited by bibiki: n/a


$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';

echo base64_decode($str);

This also decode the string...


$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';

echo base64_decode($str);

This also decode the string...

Yes i know that but the problem here is the string is generated by encoding a jpg image.. and it is done in .net application and this string is posted from the .net application to my php website.
I want to get that image back to jpg for saving that image in a folder.

This .net application is used for work monitoring and it will take the screenshot of the work doing by a programmer in the office.

Thanks for ur valuable time....


Finally i had figured it out with the help of my sir.

1)First request the encoded string image by

$encodedImage = $_REQUEST;

2) Then create an image name with ur own requirement
$imagename = $monitorId.'.jpg';
Note that the extension of the image should be the same as the image that is posted from the .net application.

3) Open a file with modes w+ or wb

$ifp = fopen(ROOT."/images/monitoring/".$imagename , "w+");

4) then replace all the spaces in the encoded string with + symbol

$encodedImage = str_replace(' ','+',$encodedImage);

5) Then write the encoded image string to the file.
while writing the encodedImage should be decoded using base64_decode ()

fwrite( $ifp, base64_decode($encodedImage));

6) fclose($ifp);

That is all... now go and look the /images/monitorig folder ... there will be ur image ready to smile for u....

Edited by jino: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.