File Upload Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chunk1978
    New Member
    • Jan 2007
    • 224

    File Upload Error

    hi there...

    i have the following codes (HTML and PHP) on my Apache Localhost:

    HTML: titled "Form.html"
    Code:
    <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>
    PHP: titled "uploader.p hp"
    Code:
    <?php
    $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!";
    }
    ?>
    i've also created a folder called "uploads" in the same directory as the .html and .php files.

    the problem i'm having is that i always get the message:

    "There was an error uploading the file, please try again!"

    i don't know what i'm doing wrong... this is the most basic php upload script... does Apache not allow files to be written to the localhost folders? or maybe the php script is wrong?

    anyone?
  • mklprasanna
    New Member
    • Apr 2007
    • 10

    #2
    Hi,

    The Code what you wrote is correct and its working.Execute once again!!

    prasanna

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      You probably have permissions set up wrong in your file system, therefor move_uploaded_f ile() is failing.

      Comment

      • chunk1978
        New Member
        • Jan 2007
        • 224

        #4
        Originally posted by Motoma
        You probably have permissions set up wrong in your file system, therefor move_uploaded_f ile() is failing.
        hi motoma, thanks for replying... i've read something about changing file permissions to 777, but i have zero idea how i could do this with Apache on my localhost... i don't use FTP to transfer files, while i read that permissions can be changed via FTP.

        Comment

        Working...