note 38479 modified in function.base64-decode by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:52:34 +0000 |
| Subject: | note 38479 modified in function.base64-decode by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80075@lists.php.net to get a copy of this message | ||
I was wondering how to decode attached images within mails. Basically they are mostly JPEG files, so
it was obviously to write a function that decodes JPEG images.
I guess the plainest way to do so was the following:
<?php
function base64_to_jpeg( $inputfile, $outputfile ) {
/* read data (binary) */
$ifp = fopen( $inputfile, "rb" );
$imageData = fread( $ifp, filesize( $inputfile ) );
fclose( $ifp );
/* encode & write data (binary) */
$ifp = fopen( $outputfile, "wb" );
fwrite( $ifp, base64_decode( $imageData ) );
fclose( $ifp );
/* return output filename */
return( $outputfile );
}
?>
This function decodes the given inputfile (a filename!) and saves it to the given outputfile (a
filename as well) and then returns the output filename for further usage (e.g. redirect, imagejpeg()
and so on).
I thought that might be helpful.
--was--
I was wondering how to decode attached images within mails. Basically they are mostly JPEG files, so
it was obviously to write a function that decodes JPEG images.
I guess the plainest way to do so was the following:
function base64_to_jpeg( $inputfile, $outputfile ) {
/* read data (binary) */
$ifp = fopen( $inputfile, "rb" );
$imageData = fread( $ifp, filesize( $inputfile ) );
fclose( $ifp );
/* encode & write data (binary) */
$ifp = fopen( $outputfile, "wb" );
fwrite( $ifp, base64_decode( $imageData ) );
fclose( $ifp );
/* return output filename */
return( $outputfile );
}
This function decodes the given inputfile (a filename!) and saves it to the given outputfile (a
filename as well) and then returns the output filename for further usage (e.g. redirect, imagejpeg()
and so on).
I thought that might be helpful.
http://php.net/manual/en/function.base64-decode.php