Page 1 of 1

Problem with ftp upload

Posted: Mon Aug 25, 2008 8:01 am
by spheriad
Hello all,
I am having a problem with uploading a file (usually a excel or word file) in my php code. Here are some snippets of code that have to do with the ftp info.

Code: Select all

 
        //setting up all variables to upload file 
        $remote_filefrm = "iso/forms/forms/".$_FILES['frm_lnk']['name'];
    $remote_fileinst = "iso/forms/instructions/".$_FILES['frm_inst']['name'];
    $filefrm = $_FILES['frm_lnk']['tmp_name'];
    $fileinst= $_FILES['frm_inst']['tmp_name'];
    $filepathfrm = "iso/forms/forms/".$_FILES['frm_lnk']['name'];
    $filepathinst = "iso/forms/instructions/".$_FILES['frm_lnk']['name'];
    $ftp_server = "10.42.45.32";
    $ftpuser = "admin";
    $ftppass = "posti";
    $conn_id = ftp_connect($ftp_server);
    $login_result = ftp_login($conn_id, $ftpuser, $ftppass);
 
        // running the query into the database and uploading the file to a "vault"
        $query = "INSERT INTO ENV_FORM (FORM_ID,FORM_NAME,FORM_LINK,FORM_INST,INST_LINK) 
        values ('$form_id','$form_name','$filepathfrm','$inst_name','$filepathinst')";
    ftp_put($conn_id, $remote_filefrm, $filefrm, FTP_ASCII);
    ftp_put($conn_id, $remote_fileinst, $fileinst, FTP_ASCII);
    DB_Insert($query);
    ftp_close($conn_id);
 
After this runs the file is moved to a folder on the ftp site and all is well, untill someone tries to open the file, then the file opens corrupted and is unreadable... I cant figure out why

Thanks in advance,
Travis

Re: Problem with ftp upload

Posted: Mon Aug 25, 2008 10:26 am
by ghurtado
Change

Code: Select all

   ftp_put($conn_id, $remote_fileinst, $fileinst, FTP_ASCII);
to

Code: Select all

   ftp_put($conn_id, $remote_fileinst, $fileinst, FTP_BINARY);

Re: Problem with ftp upload

Posted: Mon Aug 25, 2008 11:53 am
by spheriad
Tried this and it worked!! Thanks!