0

Hi everyone

I'm trying to create a PHP/MySQL script which will allow a user to enter some details about an image (.jpg or .gif or whatever) and upload it to a MySQL Table.

Now, I've got it working perfectly in Firefox 3.6.8 and in the script portion below, it outputs $msg as "Data successfully uploaded", which is correct.

But when I run the same script with Internet Explorer 8.0.6001.18702 (?) then it outputs $msg as "Error: Not a valid image".

This is the fairly simple bit of code producing these messages. There must be something in it that IE8 doesn't like?

// if Submit button is clicked
   if($_POST['Submit']) {

      // check for the image type , before uploading
      if (in_array($fileType, $image_array)) {

         // check whether the file is uploaded
         if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {
 
            // check whether the file size is below 1 mb
            if($_FILES['userfile']['size'] < $maxFileSize) {
               
               // Getting Size and Type of image from $_FILES
               $imageType = $_FILES['userfile']['type'];
               $imageSize = $_FILES['userfile']['size'];
 
               // reading the image data
               $imageData = mysql_real_escape_string(file_get_contents($_FILES['userfile']['tmp_name']));

               // inserting into the database
               $sql = "INSERT INTO image (imageData, imageName, imageWidth, imageHeight, imageType, imageSize) VALUES ('$imageData','$imageName','$imageWidth','$imageHeight','$imageType','$imageSize')";
 
               mysql_query($sql) or die(mysql_error());
               $msg = "Data successfully uploaded";
            }
            else {
               $msg = 'Error: File size exceeds the maximum limit';
            }
         }
      }
      else {
         $msg = 'Error: Not a valid image';
      }

   }

So if there are any experts out there, I would very much appreciate being pointed in the right direction to solve this problem.

Thanks
Terry

4
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by metalix
0

I think we actually need more information about this. The problem itself is quite simple, though: the condition "if (in_array($fileType, $image_array))" is not met.

Start debugging you code:
make an output of $fileType and $image_array right before the condition and let the code run under FF and IE. I guess you'll then already see the problem. If you still have trouble, then paste the output here.

Greetings Simon

0

PHP is a server-side language. It could care less what browser you are using.

I'm going to take a total shot in the dark and say if this works in FF and not in IE then it has something to do with how the data is being passed from your form.

I would like to see the generated form HTML and also the php what is being used to set the variable $fileType. I'm assuming $image_array is an array of file types you're checking against as well.

0

If this is uploading images to a database try this tutorial
if it works in firefox, then it has to be a browser issue when passing the data.
please post your form

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.