SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with simple upload script

    I'm trying to work on an upload script ... and I can't really see why it isn't working. I'm trying to upload a file and then move it into a directory called "test" which is in the same directory as the php file.

    As you can see, I've put an if() statement into my code to see whether this would work or not ... and I'm getting an output on the screen saying "File moved" which suggests that it has worked. Unfortunately though, there is no file in the directory.

    Can anybody suggest where I'm going wrong?

    Any help would be really appreciated.

    Thanks alot

    PHP Code:
    <html>
    <head>
    <title>Uploading a File</title>
    </head>

    <body>
    <?php
    if (isset($_FILES['fupload'])){

        
    $source=$_FILES['fupload']['tmp_name'];
        
    $target="test/".$_FILES['fupload']['name'];
        
            if(
    move_uploaded_file($source$target)){
                print 
    "File Moved";
            }

            else{
                print 
    "Problem moving file";
            }

        }
    ?>
    <form enctype="multipart/form-data" action="<?print $_SERVER['PHP_SELF']?>" method="post">
    <p>
    <input type="file" name="fupload">
    <input type="submit" value="Upload">
    </form>
    </body>
    </html>

  2. #2
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by simontheak
    I'm trying to work on an upload script ... and I can't really see why it isn't working. I'm trying to upload a file and then move it into a directory called "test" which is in the same directory as the php file.

    As you can see, I've put an if() statement into my code to see whether this would work or not ... and I'm getting an output on the screen saying "File moved" which suggests that it has worked. Unfortunately though, there is no file in the directory.

    Can anybody suggest where I'm going wrong?

    Any help would be really appreciated.

    Thanks alot

    PHP Code:
    <html>
    <head>
    <title>Uploading a File</title>
    </head>
     
    <body>
    <?php
    if (isset($_FILES['fupload'])){
    $source=$_FILES['fupload']['tmp_name'];
    $target="test/".$_FILES['fupload']['name'];
    if(
    move_uploaded_file($source$target)){
    print 
    "File Moved";
    }
    else{
    print 
    "Problem moving file";
    }
    ?>
    <form enctype="multipart/form-data" action="<?print $_SERVER['PHP_SELF']?>" method="post">
    <p>
    <input type="file" name="fupload">
    <input type="submit" value="Upload">
    </form>
    </body>
    </html>
    Is there more to this file because Im not seeing the } for the first if statement. Also dont see:



    Silly

  3. #3
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Silly - thanks for replying.

    I'm afraid that's just my bad copying and pasting ... I've edited the post above to include the extra curly bracket.

    Thanks,

  4. #4
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by simontheak
    Hi Silly - thanks for replying.

    I'm afraid that's just my bad copying and pasting ... I've edited the post above to include the extra curly bracket.

    Thanks,
    Ok, then:

    <input type="hidden" name="MAX_FILE_SIZE" value="30000">

    Before the text field, which is required.

  5. #5
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I've done as you suggested and I initally got a problem with the MAX_FILE_SIZE being too low, so I've increased it and now I'm back to the same problem: the if() statement saying that the file has moved, but no file in the "test" directory.

  6. #6
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's alright now - problem averted!

    Thanks very much for all your help Silly


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
  •