38 $result = explode(
',', $uri->path, 2);
43 list($metadata, $data) =
$result;
45 $metas = explode(
';', $metadata);
46 while (!empty($metas)) {
47 $cur = array_shift($metas);
48 if ($cur ==
'base64') {
52 if (substr($cur, 0, 8) ==
'charset=') {
55 if ($charset !== null) {
58 $charset = substr($cur, 8);
60 if ($content_type !== null) {
69 if ($content_type !== null && empty($this->allowed_types[$content_type])) {
72 if ($charset !== null) {
76 $data = rawurldecode($data);
78 $raw_data = base64_decode($data);
84 $file = tempnam(
"/tmp",
"");
85 file_put_contents(
$file, $raw_data);
86 if (function_exists(
'exif_imagetype')) {
87 $image_code = exif_imagetype(
$file);
89 } elseif (function_exists(
'getimagesize')) {
90 set_error_handler(array($this,
'muteErrorHandler'));
91 $info = getimagesize(
$file);
92 restore_error_handler();
97 $image_code = $info[2];
99 trigger_error(
"could not find exif_imagetype or getimagesize functions", E_USER_ERROR);
101 $real_content_type = image_type_to_mime_type($image_code);
102 if ($real_content_type != $content_type) {
105 if (empty($this->allowed_types[$real_content_type])) {
108 $content_type = $real_content_type;
111 $uri->userinfo = null;
114 $uri->fragment = null;
116 $uri->path =
"$content_type;base64," . base64_encode($raw_data);