SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Temp file from file upload is missing

    I'm trying to upload a CSV file to process in PHP. I was getting an error, so I put in some debuggin code. Here's what I have:

    Code:
    <form name="update" action="update.php" enctype="multipart/form-data" method="post">
    <input type="file" name="memberlist"><br>
    <input type="submit" name="submit" value="Update">
    <input type="hidden" name="FormSubmit" value="TRUE">
    </form>
    Once uploaded, I did this for testing:

    Code:
    <?php
    if(isset($_POST['FormSubmit'])){
    print $_FILES['memberlist']['size'] . "<br>\n";
    print $_FILES['memberlist']['tmp_name'] . "<br>\n";
    print $_FILES['memberlist']['error'] . "<br>\n";
    }
    ?>
    This was displayed:

    Code:
    10055
    C:\DOCUME~1\XPUSER~1\LOCALS~1\Temp\php461.tmp <- Just for my local testing server, not production :)
    0
    When I check that directory, the .tmp file isn't there and the move_uploaded_file function is returning false. File Uploads are ON. What am I missing here?

    Thanks for the help!

  2. #2
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Aha! Found the problem!

    I was fixated on the lack of a file in the temp directory. Turns out that temp uploads are not saved after script finishes. So, I turned to the path I was trying to move to.

    The variable $_SERVER['DOCUMENT_ROOT'] does not have a trailing '/'. Doh!

    I changed the path to $_SERVER['DOCUMENT_ROOT'] . '/uploads/data.csv' and it worked fine.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, this from the user comments to "Handling File Uploads" at php.net:
    Hello everyone. I want to share to you that uploading will never work out of the box if you didn't set the upload_tmp_dir directive in your php.ini file in the first place. If you just compiled the source files as is and tried to upload, you're in for a big mess. I don't know the flags to pass to the configure script to tell php about the default temporary directory to place the uploaded files.

    In case your php upload code won't do as expected, open up the php.ini file and set the upload_tmp_dir. Then restart the Apache server and you're set.


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
  •