The easiest way to add a block to the end of a deleted file is to use file_put_contents with the FILE_APPEND flag:
file_put_contents('ftp://username:pa ssword@hostname /path/to/file', $chunk, FILE_APPEND);
If this does not work, perhaps because you do not have URL wrappers enabled in PHP .
If you need more control over the recording (transfer mode, passive mode, etc.) or you cannot use file_put_contents , use ftp_fput with the ftp_fput descriptor php://temp (or php://memory ) :
$conn_id = ftp_connect('hostname'); ftp_login($conn_id, 'username', 'password'); ftp_pasv($conn_id, true); $h = fopen('php://temp', 'r+'); fwrite($h, $chunk); rewind($h); // prevent ftp_fput from seeking local "file" ($h) ftp_set_option($conn_id, FTP_AUTOSEEK, false); $remote_path = '/path/to/file'; $size = ftp_size($conn_id, $remote_path); $r = ftp_fput($conn_id, $remote_path, $h, FTP_BINARY, $size); fclose($h); ftp_close($conn_id);
(add error handling)
source share