Results 1 to 4 of 4

Thread: php upload script

  1. #1
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default php upload script

    PHP Code:
    if ($action == "load") {
      if(!empty(
    $_FILES["userfile"])) {
        
    $uploaddir $home $path $_FILES["userfile"]["name"];
        
    //Copy the file to some permanent location
        
    if(move_uploaded_file($_FILES[userfile]["tmp_name"], $uploaddir)) {
          echo 
    'The file was uploaded successfully! Please click <a href="?path='.$path.'">here</a> to continue.';
        } else {
          echo 
    'An error occured while trying to upload the file! Please click <a href="?path='.$path.'">here</a> to return to the File Manager.';
          
    print_r($_FILES);
        }
      } else {
    print_r($_REQUEST);}
    } else {
      echo 
    '<form method="POST">
      <input type="hidden" name="action" value="load" />
      Send this file: <input name="userfile" type="file" />
      <input type="submit" value="Upload" />
      </form>'
    ;
    }


    I get the Request data(will be taken out once the scipt works) instead of a conformation message.
    Im doing something wrong, but i dont know what.
    PS: "$_FILES" is not empty, b/c i get this...
    Array ( [path] => upload/ [act] => load [action] => load [userfile] => /home/boxxertrumps/snapshot1.png )
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

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

    Default

    You have to put in the enctype as multipart/form-data. An example:

    Code:
    <form method="POST" enctype="multipart/form-data">
    That should do it. Hope this helps.
    Last edited by thetestingsite; 03-12-2007 at 09:20 PM.
    "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

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Yep, you have to use it when using the pre-defined $_FILES variable. Look here for why:
    http://www.htmlcodetutorial.com/form...M_ENCTYPE.html
    - Mike

  4. #4
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    First time writing an upload *anything*... thanks.

    Upload works now... should have done more research.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

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
  •