X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplupload.php;h=743a0907ee926a4764dbd3a4e6c2e18b3a29805b;hb=02838718a24585bf72f3e4c26a8e4f1d19817dc9;hp=d5f428f6b42dec530d7095c763974e7815793243;hpb=155819d9ece12a06d37df46e22b76e3c71f65fba;p=platal.git diff --git a/classes/plupload.php b/classes/plupload.php index d5f428f..743a090 100644 --- a/classes/plupload.php +++ b/classes/plupload.php @@ -89,6 +89,10 @@ class PlUpload public function download($url) { + if (!$url || @parse_url($url) === false) { + trigger_error('malformed URL given', E_USER_NOTICE); + return false; + } $data = file_get_contents($url); if (!$data) { return false; @@ -158,9 +162,28 @@ class PlUpload return $this->type; } + public function isType($type, $subtype = null) + { + list($mytype, $mysubtype) = explode('/', $this->type); + if ($mytype != $type || ($subtype && $mysubtype != $subtype)) { + return false; + } + return true; + } + public function imageInfo() { - return getimagesize($this->filename); + static $map; + if (!isset($map)) { + $map = array (1 => 'gif', 2 => 'jpeg', 3 => 'png'); + } + $array = getimagesize($this->filename); + $array[2] = @$map[$array[2]]; + if (!$array[2]) { + trigger_error('unknown image type', E_USER_NOTICE); + return null; + } + return $array; } public function resizeImage($max_x = -1, $max_y = -1, $min_x = 0, $min_y = 0, $maxsize = -1) @@ -170,15 +193,11 @@ class PlUpload return false; } $image_infos = $this->imageInfo(); - if (empty($image_infos)) { + if (!$image_infos) { trigger_error('invalid image', E_USER_NOTICE); return false; } list($this->x, $this->y, $mimetype) = $image_infos; - if ($mimetype < 1 || $mimetype > 3) { // 1 - gif, 2 - jpeg, 3 - png - trigger_error('unknown image type', E_USER_NOTICE); - return false; - } if ($max_x == -1) { $max_x = $this->x; }