View Full Version : image upload, image type check not working
Paul Ferrie
01-26-2005, 06:04 PM
I have been having problems with this for some time
$types_array = array("image/gif","image/jpeg","image/pjpeg","image/jpg","image/x-png");
//Check file against array
if (!in_array($_FILES['userfile']['type'], $types_array)) {
//Return error if file typ dosnt match array
header("Location: addImage.php?error=That file type is not allowed!");
exit;
}
It will only allow me to upload gif format. i get file type not allowed for jpg files and png files :(. Does any one have an idea why this is not working.
Cheers
Paul
petefs
01-26-2005, 07:22 PM
Are you using firefox/netscape to upload the images? There are mime type problems with those browsers.
Paul Ferrie
01-26-2005, 07:26 PM
no i am using ie
Paul Ferrie
01-26-2005, 07:46 PM
Just had a thought. What about using substr to get the last 3 characters of the filename then check the ext against an array of ext type?
Mateusz
01-26-2005, 07:53 PM
All you've got to do is to check $_FILES['userfile']['type'] when you're uploading jpg file for example
echo($_FILES['userfile']['type']);
You can check uploaded file with getimagesize (http://pl2.php.net/function.getimagesize) too.
Paul Ferrie
01-28-2005, 07:41 PM
This is doing my head in :mad: :mad: :mad: :mad: :mad:
I have just tried again on a different server and still it wont work.
Try yourselfs
http://www.innovativedesigns.me.uk/sensua/php/adm/addimage.php
Image type is returned empty if i try to upload a jpg
but it works fine for gif format
Mateusz
01-28-2005, 10:09 PM
Did you check getimagesize function?
Are you sure that the file is upladed properly? Can you check its size for example? Only image type is empty?
Dark_Element
01-29-2005, 12:44 AM
Errrh are you sure you have the right enctype? cos this code works in IE and FF:
<?php
if (isset($_POST['send'])) {
$types_array = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/x-png', 'image/png');
if (!in_array($_FILES['userfile']['type'], $types_array)) {
echo('nah not found in array<br />');
}
echo($_FILES['userfile']['type']);
}
?>
<br />
<form method="post" enctype="multipart/form-data" action="<?php echo($_SERVER['PHP_SELF']); ?>">
<input type="file" name="userfile" size="20" /><input type="submit" name="send" value="Hit It" />
</form>
Are you sure that both hosts your using supports file upload handeling through POST capabilities?
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.