SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image upload not working for IE or firebox

    Hi,

    I have a file upload script that uses a iframe to load a image to the server while staying on the same page but for some reason it only works in google chrome and not IE or firefox, can anybody help with this...

    here's the main part of the code for the upload of the image

    Code:
    function startUpload() {
      document.getElementById('photo_uploader').innerHTML="<img src='images/loader.gif' />";
      return true;
    }
    
    function stopUpload(result) {
      if (result == 1) {
        alert('update image');
      }
    }
    
    <!-- BODY BELOW -->
    
    <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
                  <div id="photo_uploader">
                    <form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload()">
                      <input name="myfile" type="file" size="30" />
                      <input type="submit" name="submitBtn" class="sbtn" value="Upload" />              
                    </form>
                  </div>
    And here's the upload.php script below

    Code:
    $timestamp = time();
    $result = 0;
    $_FILES["myfile"]["name"] = $timestamp."_".$_FILES["myfile"]["name"];
    
    $filename = $_FILES["myfile"]["name"];
    
    if ((($_FILES["myfile"]["type"] == "image/gif") || ($_FILES["myfile"]["type"] == "image/jpeg") || ($_FILES["myfile"]["type"] == "image/pjpeg")) && 
    
    ($_FILES["myfile"]["size"] < 900000))
      {
      if ($_FILES["myfile"]["error"] > 0)
        {
        }
      else
        {
        if (file_exists("upload/" . $_FILES["myfile"]["name"]))
          {
          }
        else
          {
          $filename = "http://server/upload/".$filename;
          move_uploaded_file($_FILES["myfile"]["tmp_name"],
          "upload/" . $_FILES["myfile"]["name"]);
          $result = 1;
          $query = "UPDATE users SET url = '$filename' WHERE userid='$userID'";
          mysql_query($query);
          }
        }
      }
    else
      {
    
      }
    sleep(1);
    ?>
    
    <script language="javascript" type="text/javascript">parent.stopUpload(<?php echo $result; ?>);</script>
    is it something to do with the parent.Function as to why it doesn't work in IE or firefox?

    Thanks in advance?

  2. #2
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not realy familiar with PHP but does it throw any errors or is it simply not uploading? Another question! Do you use the Iframe to stay on the page? In my knowledge you don't need a IFrame for that. I think you need some kind of exception handling to see what's going on.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well this is a script from http://www.ajaxf1.com/product/ajax-file-upload.html

    it uses the iframe to stay on the same page while uploading the image.

    The funny thing is it works perfect for google chrome browser as in it uploads the image but i can't seem to get it to work in IE or firefox...

    Has anyone used the above script to upload files? is it cross-browser compatible?


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
  •