Dear folks,
I'm working on a page which needs to handle base64-encoded jpg files. I need to decode them and be able to use it further on on the for viewing. I do not want a jpg-onky page with the result, but need to place it in a table, etc. Problem is, with my current script (see below), the encoded file gets copied, renamed and is usable for viewing, but next this image just resides on the server, while it should be deleted after the image is loaded onto the client's screen. I tried to delete the copied file after the lines of code to display the image, but then the browser says no image is found....
How can I solve this problem ? I'm no genius in PHP (i'm an ASP programmer) so I've tried everything my PHP knowlegde ables me to...
Hope to hear from you !
Code:
<?php
//READ FILE NAME TO VIEW FROM POST VARS:
//--------------------------------------
import_request_variables("P", "mypost_");
// DEFINE VARS:
//-------------
$imagename = $mypost_filename;
$imagetitle = $mypost_imagetitle;
$secured_imagename = $imagename.".php";
$path = "yourmammasuploads/";
$targetpath = $path.$secured_imagename;
$tempfile = $targetpath.".jpg";
//REMOVE SECURITY LINE IN FILE AND DECODE FILE CONTENTS:
//------------------------------------------------------
$data = file($targetpath);
array_shift($data);
$data = implode('', $data);
$file = base64_decode($data);
// WRITE NEW NON-SECURED TEMPORARY FILE FOR VIEWING:
//--------------------------------------------------
$f = fopen($tempfile, 'w');
fwrite($f, $file);
fclose($f);
//ALL DONE
//--------
echo "All done. Temp image ready for viewing:<br><br>";
echo "<img src='" . $tempfile . "'><BR>";
echo $imagetitle;
EXIT;
?>
Regards,
Roel