Skipjackrick Posted January 7, 2010 Share Posted January 7, 2010 I've got a photo upload script where I verify the file type. For some reason it sends me to my error message when I upload the correct file using IE. It works fine in Firefox. Any clues? Maybe you guys have a better way of verifying file type. But I only want jpg files. <?php // name of the fieldname used for the file in the HTML form $fieldname = 'file'; // Now let's deal with the upload // possible PHP upload errors if (($_FILES["file"]["type"] == "image/jpeg")) { $errors = array(1 => 'php.ini max file size exceeded', 2 => 'html form max file size exceeded', 3 => 'file upload was only partial', 4 => 'no file was attached'); // check the upload form was actually submitted else print form isset($_POST['submit']) or error('the upload form is neaded', $uploadForm); // check for standard uploading errors ($_FILES[$fieldname]['error'] == 0) or error($errors[$_FILES[$fieldname]['error']], $uploadForm); // check that the file we are working on really was an HTTP upload @is_uploaded_file($_FILES[$fieldname]['tmp_name']) or error('not an HTTP upload', $uploadForm); // validation... since this is an image upload script we // should run a check to make sure the upload is an image @getimagesize($_FILES[$fieldname]['tmp_name']) or error('only image uploads are allowed', $uploadForm); // make a unique filename for the uploaded file $uploadFilename = $uploadsDirectory.$anglerId.'avatar.jpg'; // now let's move the file to its final and allocate it with the new filename @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename) or error('receiving directory insuffiecient permission', $uploadForm); $image_name = $anglerId.'avatar.jpg'; $q = "UPDATE anglers SET avatar='$image_name', avatar_active=1 WHERE anglerId=$anglerId"; $s = mysql_query($q, $db); //if an error echo(mysql_error()); // If you got this far, everything has worked and the file has been successfully saved. // We are now going to redirect the client to the success page. header('Location: ' . $uploadSuccess); } else { header("Refresh: 5; URL=addaprofile_photos.php"); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n". '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n". '<html lang="en">'."\n". ' <head>'."\n". ' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n". ' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n". ' <title>Upload error</title>'."\n\n". ' </head>'."\n\n". ' <body>'."\n\n". ' <div id="Upload">'."\n\n". ' <h1>Apologies, but only JPG Files are accepted.</h1>'."\n\n". ' <p>The upload form will reload in 5 seconds</p>'."\n\n". ' </div>'."\n\n". '</html>'; exit; } ?> Link to comment https://forums.phpfreaks.com/topic/187518-strange-problem-with-ie-photo-uploader/ Share on other sites More sharing options...
RaythMistwalker Posted January 7, 2010 Share Posted January 7, 2010 how does the form look? I'm sure theres a way to set it to only select files with name *.jpg Link to comment https://forums.phpfreaks.com/topic/187518-strange-problem-with-ie-photo-uploader/#findComment-990084 Share on other sites More sharing options...
Skipjackrick Posted January 7, 2010 Author Share Posted January 7, 2010 Yeah, I checked that. The field shows the .jpg extension...... Its very strange.. I just don't get it. Link to comment https://forums.phpfreaks.com/topic/187518-strange-problem-with-ie-photo-uploader/#findComment-990085 Share on other sites More sharing options...
Skipjackrick Posted January 7, 2010 Author Share Posted January 7, 2010 Well it turns out that if you allow "image/pjpeg" OR "image/jpeg" it will work in both FF and IE. Here is how I got it working. <?php // verify image type if (!($_FILES['file']['type'] == 'image/jpeg' OR $_FILES['file']['type'] == 'image/pjpeg' )) { echo "You have encountered an error"; } ?> Link to comment https://forums.phpfreaks.com/topic/187518-strange-problem-with-ie-photo-uploader/#findComment-990514 Share on other sites More sharing options...
_Alex_ Posted January 14, 2010 Share Posted January 14, 2010 You can also use Flash multiple files uploader. It is an Open Source Edition http://quadroland.com/q_imageuploader/opensource/ You can set files filter there like (*.jpg, *.png, *.gif) Link to comment https://forums.phpfreaks.com/topic/187518-strange-problem-with-ie-photo-uploader/#findComment-994728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.