PHP Upload Question

Discussion in 'Programming' started by CCloudyVision, Oct 3, 2007.

  1. #1
    Hello,
    I have a very simple script and am not interested in security. That being said, I cannot get it to work and I was wondering if you good people could help me find out why. I am an amateur as I am sure you all can tell so please be gentle

    Form.php
    HTML:

    <form enctype="multipart/form-data" action="uploader.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
    </form>



    Uploader.php
    php:

    <html>
    <head>

    <title>Untitled</title>

    </head>
    <body>

    <?

    $target_path = "uploads/";

    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }


    ?>
    </body>
    </html>



    I copied this verbatim from one of the tutorials so I am not trying to claim this as my own but I cannot get it to work. The only message I get after trying to upload is the "There was an error..." message. Any help is appreciated. Thanks in advance.
     
    CCloudyVision, Oct 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    What are the permissions of the upload directory? Is PHP allowed to write to it?

    And I know you said you don't care about security... but honestly, do not use this anywhere in public.
     
    nico_swd, Oct 3, 2007 IP
  3. CCloudyVision

    CCloudyVision Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The directory is public. Isn't that the same as writable? There is no private info being shared with this site, so I am not concerned with security. How can I find out if PHP can wrote to the directory?
     
    CCloudyVision, Oct 5, 2007 IP
  4. EMcDonell

    EMcDonell Peon

    Messages:
    85
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think even if the directory is public you would need FTP login info to access it? maybe not...
     
    EMcDonell, Oct 5, 2007 IP
  5. Xonium

    Xonium Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    chmod folder/file to 777 in your ftp client.
     
    Xonium, Oct 5, 2007 IP