Help : Uploading File Error

Discussion in 'PHP' started by jhona, Sep 1, 2006.

  1. #1
    Hello guys,

    My bf had a problem with his code in uploading file.. I include here the codes.. Could anyone please take a look with this code and tell me what is the error. Thank you in advance.

    His message:

    
    $tempname = str_replace(" ","_",$_FILES['uploadedfile']['name']);
    $destination_file =  "uploads/".$tempname;
    
    $source_file = $_FILES['uploadedfile']['tmp_name'] ;
     
    if(copy($source_file, $destination_file)) {
                   $msg = "Uploaded $source_file to $ftp_server as $destination_file";
                   $address = $_SESSION['current_user'];
                   $fname = $_SESSION['first_name'];
                   $lname = $_SESSION['last_name'];
                   $filename = $tempname;  
                   mail("email@email.com", "File Upload by $fname $lname", "http://www.domain.net/uploads/".$filename, "From: domain.com" );
           }else{
                   $msg = "Upload Failed! Please try or check path of file to be uploaded.";
           }
    
    Code (markup):
    Thank you :)
     
    jhona, Sep 1, 2006 IP
  2. [*-AnOnYmOuS-*]

    [*-AnOnYmOuS-*] Active Member

    Messages:
    253
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Is the tmp directory properly chmodded? Because if it's not, that would mean no copy, and no file existing in the uploads section :D.
     
    [*-AnOnYmOuS-*], Sep 2, 2006 IP
  3. petronel

    petronel Peon

    Messages:
    113
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try to set $destination_file as full path.
    
    $destination_file =  "/home/account/public_html/uploads/".$tempname;
    
    Code (markup):
    also make sure uploads folder exist and permisions are 777.

    if doesn't work, add
    print_r($_FILES['uploadedfile']);
    Code (markup):
    and paste the results.
     
    petronel, Sep 2, 2006 IP
  4. petronel

    petronel Peon

    Messages:
    113
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    also you could replace copy with move_uploaded_file
     
    petronel, Sep 2, 2006 IP
  5. fakhruddin

    fakhruddin Peon

    Messages:
    193
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i think this is chmod problem
    chmod the upload folder "777"
     
    fakhruddin, Sep 2, 2006 IP
  6. jhona

    jhona Peon

    Messages:
    96
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you guys for all the reply... :) it helps a lot to my boyfriend to figure out the error.

    Here is what he sed
    Well... I'm very happy to be a part of this forum, there's a lot of very helpful member member.

    Thanks again, I hope someday I can also help someone... :) regarding with PHP code.
     
    jhona, Sep 2, 2006 IP