Problem with ftp upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spheriad
Forum Newbie
Posts: 2
Joined: Mon Aug 25, 2008 7:55 am

Problem with ftp upload

Post 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
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Problem with ftp upload

Post 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);
spheriad
Forum Newbie
Posts: 2
Joined: Mon Aug 25, 2008 7:55 am

Re: Problem with ftp upload

Post by spheriad »

Tried this and it worked!! Thanks!
Post Reply