Problem using PHP upload

Discussion in 'PHP' started by NoamBarz, Aug 6, 2008.

  1. #1
    For some reason, this script isn't working:

    
    if(isset($_FILES["uploadedfile"])){
      
      // upload file
      //---------------------------------------------------------------------------
      $target_path = "uploads/Signature";
      if(!is_dir($target_path)){
        mkdir($target_path, 0755);
        chmod($target_path, 0777);
      }
      else chmod($target_path, 0777);
      
      $target_path .= "/" . basename( $_FILES['uploadedfile']['name']);
      
      if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        print_r($_FILES);
        die("problem uploading file");
      }
    }
    
    Code (markup):
    Here's the uotput I get:

    Array ( [uploadedfile] => Array ( [name] => RavgonLogoSmall.gif [type] => image/gif [tmp_name] => C:\WINDOWS\Temp\phpB46A.tmp [error] => 0 [size] => 8175 ) ) problem uploading file


    There dosn't seem to be a problem with the script, but the file won't upload.
    I know it fails the "move_uploaded_file" function, but have no idea what kind of error is taking place. Any ideas how I can debug this? I'm pretty sure it has to do with permissions.

    Thank
     
    NoamBarz, Aug 6, 2008 IP
  2. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try removing the basename function, at a guess that might be it:
    if(isset($_FILES["uploadedfile"])){
      
      // upload file
      //---------------------------------------------------------------------------
      $target_path = "uploads/Signature";
      if(!is_dir($target_path)){
        mkdir($target_path, 0755);
        chmod($target_path, 0777);
      }
      else chmod($target_path, 0777);
      
      $target_path .= "/" . $_FILES['uploadedfile']['name'];
      
      if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        print_r($_FILES);
        die("problem uploading file");
      }
    }
    Code (markup):
    PS: Please don't post two threads on the same thing...
     
    Pos1tron, Aug 6, 2008 IP