Diğer makine destekleri REST komutu (belirli bir noktadan itibaren yeniden başlatma yükleme) ftp sunucusu uygulamak için kirli bir yolu varsa:
- geçici dosya oluşturmak
- Yüklemek istediğiniz dosyayı bu dosyaya X bayt koymak
- geçici dosya upload
- başka bir dosyaya durumunu yazmak (veya oturumda, ama emin değilim bu iş olacak eğer)
- temp dosyasına başka bir X bayt append
- Form X bayt başlayan geçici dosyası yükle
- Dosyaya kriter durum
- tüm dosya yüklenene kadar 5-7 tekrarlayın
- temp & silme durum dosyaları.
Örnek kod:
$fs = filesize('file.bin');
define('FTP_CHUNK_SIZE', intval($fs * 0.1) ); // upload ~10% per iteration
$ftp = ftp_connect('localhost') or die('Unable to connect to FTP server');
ftp_login($ftp, 'login', 'pass') or die('FTP login failed');
$localfile = fopen('file.bin','rb');
$i = 0;
while( $i < $fs )
{
$tmpfile = fopen('tmp_ftp_upload.bin','ab');
fwrite($tmpfile, fread($localfile, FTP_CHUNK_SIZE));
fclose($tmpfile);
ftp_put($ftp, 'remote_file.bin', 'tmp_ftp_upload.bin', FTP_BINARY, $i);
// Remember to put $i as last argument above
$progress = (100 * round( ($i += FTP_CHUNK_SIZE) / $fs, 2 ));
file_put_contents('ftp_progress.txt', "Progress: {$progress}%");
}
fclose($localfile);
unlink('ftp_progress.txt');
unlink('tmp_ftp_upload.bin'); // delete when done
Ve ajax ile kontrol dosyası:
if(file_exists('ftp_progress.txt'))
echo file_get_contents('ftp_progress.txt');
else
echo 'Progress: 0%';
exit;