SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with move_uploaded_file

    Hi there. Having a small issue in formulating a file upload to my directory. I have properly added the extension to my mysql database (added along with other registration information), but am having a problem putting the file in the directory. Everything else works perfectly, but can't seem to properly move the uploaded file to my directory.

    If anyone can spot my oversight, I would be very grateful. Thanks in advance for taking a moment to provide your input.

    Here is the relevant php:

    PHP Code:
    $user_pic $_FILES['user_pic'];

    $id mysql_insert_id();
    $newname "avatar.jpg";
    $location "members/$id/pictures/$newname";

    mkdir("members/$id"0755);
    mkdir("members/$id/pictures"0755true);  

    $name $_FILES['user_pic']['name'];
    $tmp_name $_FILES['user_pic']['tmp_name'];
    move_uploaded_file($tmp_name"members/$id/pictures/".$newname); 
    And the form portion:

    Code:
    <input type='hidden' name='MAX_FILE_SIZE' value='16777216'>
    <td width="521"><input name="user_pic" type="file" class="formFields" size="42" /> 2mb max</td>
    Thanks again for looking at my problem.

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you used is_uploaded_file() to check if a file was actually uploaded before trying to move it to its final location?

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    What errors are you getting?

    echo out (or use var_dump() ) the value of $_FILES['user_pic'['error'] for an error value.

    Have you checked the file permissions for the destination folder?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when using var_dump for both:

    PHP Code:
    $_FILES['user_pic']['error']
    $_FILES['user_pic']['tmp_name'
    I get a 'NULL' value. I'm not sure why there is no temp file? The permissions are properly aligned, as well: Both the directories and the script are set to 0755.

    Thanks for any insight. I really appreciate the support.

  5. #5
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry. I made an elementary mistake: forgetting to set the enctype to "multipart/form-data". Thank you for your insights into properly checking for errors.


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
  •