SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Issue With Image Upload Using $_FILES

    I'm hoping someone can give me some insights on this, because I'm a little puzzled. I have a script that allows a user to upload product information, including an image. (I'm still in the coding/testing stage.) But, I keep running into a weird issue: when I browse and find the file I want to upload, it won't always upload it. I've put in echo statements to check values, for instance, the "tmp_name" value of the $_FILES array. When it comes back empty, I know it's not being uploaded. But, this is the weird part: it doesn't follow any pattern. I'll choose an image, hit upload, and it doesn't take. I'll choose another, same thing. I may do that three, four, or however many times, and then one will upload. (I also have a copy statement so I know if the image is being sent from the temp folder to its new destination.)

    For a while I thought it might be a cache issue, but adding the cache settings for the header didn't help. I even took the code out of the page I was working on and inserted it into a bare-bones page, but still no success. Does anyone know of any factors that may be causing this?

    (Tested in FF3 and IE7. Running Apache 2.2.)

    Since I was still having the same problem with the "bare-bones" code, I figured I'd post that, so it'll be less to look through. Thanks in advance! If you need more info, let me know.

    (Also, I apologize in advance if there is a really simple answer. I've tested it myself, looked around online, and can't seem to find one.)

    -------------------------------------------------------------------

    <?php
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', FALSE);
    header('Pragma: no-cache');
    ?>
    <html>
    <head><title>test</title></head>
    <body>
    <form id="frmProductAdd" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"
    onsubmit="javascript:return validateProductAdd();">
    <label for="flImg" id="flImg">Product Image: </label>
    <input type="file" class="txtMed" id="flImg" name="flImg" maxlength="300" />

    <input type="submit" id="btnSubmit" name="btnSubmit" value="Submit" />

    file uploaded?:
    <?php

    echo "File name: ".$_FILES['flImg']['tmp_name'];

    if (is_uploaded_file($_FILES['flImg']['tmp_name']) and copy($_FILES['flImg']['tmp_name'],"photos/newpic.jpg")){
    echo "<p>File stored</p>";
    }else{
    echo "<p>Not stored</p>";
    }
    ?>
    </form>

    </body>
    </html>
    Last edited by katendarcy; Dec 1, 2008 at 14:43.


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
  •