SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    class method works in firefox but not in IE, why?

    Hello everybody,

    I'm working on a class which uploads images and one of the method that evaluates the file type works in FireFox but not in IE it throws the error message I have in the script.

    Running: Firefox version 19 and IE 8.
    I cleared both browser cache and history and still no go..

    any ideas as to whats happening?


    PHP Code:
    public function imageType()  
    {    for(
    $x=0$x count($_FILES['data']['name']); $x++)
        {    if(!empty(
    $_FILES['data']['name'][$x]))
            {    if(!
    in_array($_FILES['data']['type'][$x], $this->allowedType))
                {    
    $this->errCheck[] = array('Image format not allowed: '$_FILES['data']['name'][$x]);  }
            }                    
        }


  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    What is the error as it sounds like a JavaScript issue since PHP executes before the browser renders the page, I have never seen a use case where PHP code fails in a specific browser.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by chris.upjohn View Post
    What is the error as it sounds like a JavaScript issue
    How can it be a JavaScript issue? The script that the OP posted is supposed to be processing uploaded images from a form when they get to the server - as they have PHP on the server there is unlikely to be any JavaScript on the server interfering.

    See http://support.microsoft.com/kb/815455 which explains how Internet Explorer doesn't always set the MIME type correctly when uploading files - presumably while that particular example doesn't exactly match this situation, it is an explanation on why server side code that will work with all other browsers doesn't always work for IE and the cause here is probably similar with IE not setting the correct MIME type for some types of image. To fix it I'd see just what MIME types IE does send for the various valid image types and add them into the array.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    First thing to do when tackling an issue is put var_dump($variableYouWantToCheck); in your CODE!

    You need to see what you are getting for $_FILES from both browsers and see how that impacts your code, if it isn't what you expected to receive. Placing the following above your for loop should help
    PHP Code:
    var_dump($_FILES); 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello Everybody,

    I greatly appreciate everybodys help with this problem.

    After posting the message on Sitepoint I did a quick search and came to the same conclusion as Felgalls reply. I'm not an expert on the matter but in my case IE wasn't correctly setting the MIME type.

    Correction made from:

    public $allowedType = array(
    'image/gif',
    'image/jpg',
    'image/jpeg',
    'image/png', );

    To fix the problem, see highlighted values below:

    public $allowedType = array(
    'image/gif',
    'image/jpg',
    'image/jpeg',
    'image/pjpeg',
    'image/png',
    'image/x-png',);


    Cheers.

    again thanks for everybodys help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •