note 45168 added to features.file-upload
| From: | therhinoman at hotmail dot com | Date: | Fri, 27 Aug 2004 20:20:45 +0000 |
| Subject: | note 45168 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75458@lists.php.net to get a copy of this message | ||
If your upload script is meant only for uploading images, you can use the image function
getimagesize() (does not require the GD image library) to make sure you're really getting an
image and also filter image types.
<?php getimagesize($file); ?>
...will return false if the file is not an image or is not accessable, otherwise it will return an
array like the following...
Array
(
[0] => 750
[1] => 139
[2] => 2
[3] => width="750" height="139"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
<?php
$file = somefile.jpg;
# assuming you've already taken some other
# preventive measures such as checking file
# extensions...
$result_array = getimagesize($file);
if($result_array != FALSE) {
$mime_type = $result_array['mime'];
switch($mime_type) {
case "image/jpeg": echo "file is jpeg type";
break;
case "image/gif": echo "file is gif type";
break;
default: echo "file is an image, but not of gif or jpeg type";
break;
}
}
else {
echo "file is not a valid image file";
?>
using this function along with others mentioned on this page, image uploading can be made pretty
much fool-proof.
See http://ca2.php.net/manual/en/function.getimagesize.php
for supported image types and more info.
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45168
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45168&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45168&report=yes
Search -- http://master.php.net/manage/user-notes.php