Page 1 of 1

fetching files using fopen and fb_fput

Posted: Thu Nov 19, 2009 2:45 am
by fubariser
Hi, I was wondering if there was a way to grab files from the client's local directory? I have been testing it on localhost and in my neglect I thought it was grabbing the files correctly in my intent.

here's a sample but dirty code ive been using for testing..

Code: Select all

 
 
// set the ftp settings,
$ftp_server = 'somedomain.com;
$ftp_user_name = 'user';
$ftp_user_pass = '1234';
 
// set the directory and file settings
$dir = 'D:\'';
$file = 'sample.xml';
$path = $dir . $file;
 
// make the connection
$fp = fopen($path,"r");
$conn_id = ftp_connect($ftp_server,21);
 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$ret = ftp_nb_fput($conn_id , $file , $fp , FTP_BINARY);
 
while($ret == FTP_MOREDATA){
    
    print ftell($fp);
    echo "\n";
    $ret = ftp_nb_continue($conn_id);   
 
}
 
if ($ret == FTP_FINISHED) {
 
    echo 'file upload complete';
    exit(1);
    
}
fclose($fp);
 
 
What I'm implementing is for a php page to automatically grab an xml file (from the user requesting the page) upon giving it a poke.

Thanks,
:)