Results 1 to 8 of 8

Thread: File Upload Error

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default File Upload Error

    I created a little script to upload files, but I keep getting an error while uploading. Here is my code:
    PHP Code:
    <?php
        
    if($_POST['upload']) {

    $path $_POST['path'];
    $upload_path $path basename($_FILES['file']['name']);

    if(
    move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
        
        echo 
    'The file: '.$_FILES['file']['name'].' has been uploaded. <br /> Details:';
        echo 
    'File Type '.$_FILES['file']['type'].' <br />
        File Size: '
    .$_FILES['file']['size'].' <br />
        File Name: '
    .$_FILES['file']['name'].'';
    }

    else {
        
        echo 
    'There was an error while uploading the file!';
    }
    }
    ?>
    <form method="post" action="" enctype="multipart/form-data">
        <b>File To Upload</b>:
            <br />
        <input type="file" name="file" />
            <br /><br />
        <b>Directory To Upload To</b>:
            <br />
        <input type="text" name="path" value="/directory" />
            <br /><br />
        <input type="submit" name="upload" value="Upload" />
    </form>
    I chmodded the directory I am uploading to to 777 and all, but I still get the error: "
    Warning: move_uploaded_file(uploads/): failed to open stream: Is a directory in /home/bntqann/public_html/testing/file_upload/upload.php on line 8

    Warning: move_uploaded_file(): Unable to move '/tmp/phpCNrQ1u' to 'uploads/' in /home/bntqann/public_html/testing/file_upload/upload.php on line 8
    There was an error while uploading the file!". I am at a loss as to why it is giving the error, I appreciate any help

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Haha, this is so the one I wrote
    A LONG time ago.

    I finally gave up on this particular code and started from scratch.

    There's 3 files, though, so there's too much code to post here.
    Next time you're on aim, I'll send them to you?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by alexjewell View Post
    Haha, this is so the one I wrote
    A LONG time ago.

    I finally gave up on this particular code and started from scratch.

    There's 3 files, though, so there's too much code to post here.
    Next time you're on aim, I'll send them to you?
    Your code is fancier lol.
    Anyone see an issue with my code that would be causing the error?

  4. #4
    Join Date
    Jan 2007
    Location
    Surrey, UK
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    based on a quick look... does the destination path exist?

  5. #5
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mike_p View Post
    based on a quick look... does the destination path exist?
    Yeah, I checked it a few times to make sure

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I noticed you had these two lines of code in your php, but I don't know why.

    Code:
    $path = $_POST['path'];
    $upload_path = $path . basename($_FILES['file']['name']);
    Then you have in this line for the destination, $path:

    Code:
    move_uploaded_file($_FILES['file']['tmp_name'], $path)
    Then in the rest of the script (unless you call it somewhere else), you never call upon the $upload_path variable. Maybe try switching $path with $upload_path.

    Just a suggestion.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks man, that was it. I put $path where I should have put $upload_path

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Simple mistake, happens all the time. What's even worse is when you can't find what mistake you made.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •