Parham Doustdar wrote: > Hi there, > I am writing a PHP FTP client for my project. I want to put a "download" > option and an "upload"" option, but I don't know how. My problem is this: > How can I make the server the PHP script is on delete the file after > uploading it to the SFTP, or after the user has finished downloading it from > the server the PHP script is on? > Let me put the question this way. > My server connects to an FTP. Then, it downloads a file from the FTP, and > then sends me the link to that temperary file on the server. Now, when I > download it from my server, my script should delete the file. How can I make > it wait until the download of the file is finished? > Same goes for uploading. > Thanks! >
Well if you write a download script, then you can delete it at the end and it won't be deleted until after the download completes: //Do your ftp from remote to local'/path/to/file.ext' exec('ftp_get.sh remotefile.ext /path/to/file.ext); //or $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); ftp_gett($conn_id, '/path/to/file.ext', $server_file, FTP_BINARY) ftp_close($conn_id); <?php //send proper headers for download readfile('/path/to/file.ext'); unlink('/path/to/file.ext'); ?> For upload, depending upon how you're doing it, a call to unlink() shouldn't execute until your FTP is done and exited: <?php //User uploads file to '/path/to/file.ext' exec('ftp_put.sh /path/to/file.ext); //or $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); ftp_put($conn_id, $server_file, '/path/to/file.ext', FTP_BINARY) ftp_close($conn_id); unlink('/path/to/file.ext'); ?> -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php