dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Uploading images/files

  1. #1
    Join Date
    Mar 2012
    Location
    Oklahoma
    Posts
    5

    Uploading images/files

    I am somewhat a newbie to PHP. I am trying to create a file upload. It seems to upload to the tmp directory, but fails to move when using move_upload_file(). When checking the $_FILES array after uploading, it shows that everything should be good, including 0 errors. Not sure what I'm doing wrong. HELP!

    Here is my code:

    <?php
    if (isset($_POST['submit'])) {
    if (isset($_FILES['imageUpload'])) {
    $imageName = $_FILES['imageUpload']['name'];
    echo $imageName;
    echo "<br />";
    if (move_uploaded_file($_FILES['imageUpload']['temp_name'], "uploaded/" . $imageName) == TRUE) {
    chmod("uploaded/" . $_FILES['imageUpload']['name'], 0644);
    echo "File \"" . $imageName . "\" successfully uploaded. <br />\n";
    }
    else {
    echo "There was an error uploading \"" . htmlentities($_FILES['imageUpload']['name']) . "\". <br /> \n";
    print_r($_FILES);
    }
    }
    }
    ?>

    <form action="inc_UploadImage.php" method="post" enctype ="multipart/form-data">
    Select an image to upload:
    <input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
    <input type="file" name="imageUpload"><br />
    <input type="submit" value="Upload Image" name="submit" />
    <input type="reset" value="Reset Field" name="reset" />
    </form>

  2. #2
    Join Date
    Feb 2012
    Posts
    218
    Here you will find a very good Upload tutorial: Easy way to upload with PHP and HTML

  3. #3
    Join Date
    Mar 2012
    Posts
    1
    hi

  4. #4
    Join Date
    Mar 2012
    Location
    Oklahoma
    Posts
    5

    Smile Found it!

    Finally found the mistake!

    I was putting: ['temp_name'] instead of ['tmp_name']

    Thanks for the help.

  5. #5
    Join Date
    Aug 2012
    Posts
    15
    I am also a noobie and have seen many excellent tutorial like the one linked to above, and it all makes sense except ...

    How would one do this if:

    1. The form was on one page.
    2. That form contained 2 or more “files” inputs.
    3. The upload would be done on another page?

    For example, the user enters data on one form, checks it on a second, and then the 3rd form handles the upload. How would I pass the $_FILES info along and how do I tell the upload routine to upload each file in turn?

    Thanks.

  6. #6
    Join Date
    Aug 2012
    Posts
    15
    After spending the weekend plus on this, again, self-teaching from the Internet, I figured out this would not be possible. I had been learning the syntax and all before the working concepts, and the many, many examples I read that told me how to upload files never mentioned how it all actually works.

    When you submit and enctype is set properly the file is uploaded to a temporary folder on the server. The php code on the next page (action) looks at the information provided by $_FILES, decides whether or not to accept it, and if it does it simply moves the temp file to the destination folder.

    Maybe that will help someone like myself.

    I'm still wondering is during a submit I can upload more than one file then handle that in the 'action' page's php script. When I get time I'll try a few things.

    Mike

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles