note 107705 added to function.base64-encode
| From: | jeff | Date: | Tue, 28 Feb 2012 06:36:23 +0000 |
| Subject: | note 107705 added to function.base64-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186405@lists.php.net to get a copy of this message | ||
Looking at this I feel it is a good idea and as they said it will load much quicker. Although I feel
giving the file name and the file type is a little redundant. A simple modification would solve
this, also with a little more friendly error message on fail:
<?php
function base64_encode_image ($imagefile) {
$imgtype = array('jpg', 'gif', 'png');
$filename = file_exists($imagefile) ? htmlentities($imagefile) : die('Image file name does
not exist');
$filetype = pathinfo($filename, PATHINFO_EXTENSION);
if (in_array($filetype, $imgtype)){
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
} else {
die ('Invalid image type, jpg, gif, and png is only allowed');
}
return 'data:image/' . $filetype . ';base64,' .
base64_encode($imgbinary);
}
?>
----
Server IP: 192.41.42.26
Probable Submitter: 99.32.50.209
----
Manual Page -- http://www.php.net/manual/en/function.base64-encode.php
Edit -- https://master.php.net/note/edit/107705
Del: integrated -- https://master.php.net/note/delete/107705/integrated
Del: useless -- https://master.php.net/note/delete/107705/useless
Del: bad code -- https://master.php.net/note/delete/107705/bad+code
Del: spam -- https://master.php.net/note/delete/107705/spam
Del: non-english -- https://master.php.net/note/delete/107705/non-english
Del: in docs -- https://master.php.net/note/delete/107705/in+docs
Del: other reasons-- https://master.php.net/note/delete/107705
Reject -- https://master.php.net/note/reject/107705
Search -- https://master.php.net/manage/user-notes.php