PHP upload question

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

  1. #1
    This script won't work, but I have no idea why:

    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");
    }
    }

    It only prints out the following:

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

    Any ideas? can anyone help?
     
    NoamBarz, Aug 6, 2008 IP
  2. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #2
    check the permissions on the upload folder. you need write access there.
     
    falcondriver, Aug 6, 2008 IP
  3. somanweb

    somanweb Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try the following code, you can whether the directory is writable or not

    if(is_writable ( $target_path ))
    {
    echo "Upload directory is writable";
    }
    else
    {
    echo "Upload directory is not writable";
    }
     
    somanweb, Aug 6, 2008 IP
  4. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    I tried using the is_writable function and the result is that the folder is writable.
    So it's not that. Anything wrong with the PHP? I tried eliminating the basename function and that didn't change anything either.
     
    NoamBarz, Aug 6, 2008 IP
  5. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #5
    ok I figured it out.
    I used this code to discover the error:

    $errors= error_get_last();
    echo "COPY ERROR: ".$errors['type'] . "<br/>";
    echo "<br />\n".$errors['message'] . "<br/>";

    This revealed an open stream error - permission denied. So b/c I couldn't really change the folder permissions, I switched folders to another folder on another disc and it works fine. Silly mistake.
     
    NoamBarz, Aug 7, 2008 IP