move_uploaded_file - Trying to create a folder and filename at the same time.

Discussion in 'PHP' started by facarroll, Jul 20, 2010.

  1. #1
    I have a script attached which is intended to upload an image file to a folder, but it must create a subfolder named after the primary index record id of the user.
    The receiving folder "memberFiles" has been CHMODed to 777.
    I am using an Apache server.

    I get this error message.

    Warning: move_uploaded_file(memberFiles/20/pix.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /hermes/bosweb/web121/b1215/ipg.skillsatschoolcom/demonstration/admin_login/edit_pic.php on line 31

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phppkedff' to 'memberFiles/20/pix.jpg' in /hermes/bosweb/web121/b1215/ipg.skillsatschoolcom/demonstration/admin_login/edit_pic.php on line 31
    Error.

    Any help and good advice would be much appreciated.
     

    Attached Files:

    facarroll, Jul 20, 2010 IP
  2. WhyButUs

    WhyButUs Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Before you try to move uploaded file, first try to create folder (like in this error said, memberFiles/20/) with mkdir.
     
    WhyButUs, Jul 20, 2010 IP
  3. facarroll

    facarroll Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    The problem with that approach is that I need to create a unique folder for each upload... but maybe not. I think I see the light. I can name the file by referring to the logged in id for the variable. It will still be a unique filename.
    I'll try that, but not tonight. Thanks for your comment.
     
    facarroll, Jul 20, 2010 IP
  4. facarroll

    facarroll Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    I have solved this myself. As usual, after two days of struggle, the solution was so simple.
    Question: How do I mark this as solved?
     
    facarroll, Jul 20, 2010 IP
  5. phpl0v3r

    phpl0v3r Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    lol you should really use getcwd()
    :D
     
    phpl0v3r, Jul 20, 2010 IP
  6. WhyButUs

    WhyButUs Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Post your solution, someone may find it useful too
     
    WhyButUs, Jul 20, 2010 IP
  7. facarroll

    facarroll Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #7
    I really don't see the relevance of referring to getcwd(). Would you like to explain, and in the context of the thread?
     
    facarroll, Jul 20, 2010 IP