我擅长使用PHP FTP函数上传文件。如果文件不太大,一切顺利。但是当文件大小变得很大时,就会失败。
因此,我需要一个连接到FTP并分块上传文件的代码示例。
这是我的现有代码:
$ftp_server = ftp_server;
$ftp_user_name=ftp_user_name;
$ftp_user_pass=ftp_user_pass;
$file = $_FILES["file"]["tmp_name"];
$remote_file = 'uploads/'.$_GET['file_name'];
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
if ( ftp_put($conn_id, $remote_file, $file, FTP_BINARY) ) echo "Success"; else echo "Error";
ftp_close($conn_id);
更新
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass an id...
container: document.getElementById('container'), // ... or DOM Element itself
url : 'upload.php',
flash_swf_url : '../js/Moxie.swf',
silverlight_xap_url : '../js/Moxie.xap',
filters : {
max_file_size : '1000mb',
mime_types: [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Video files", extensions : "mp4,wmv"}
]
},
init: {
PostInit: function() {
document.getElementById('filelist').innerHTML = '';
document.getElementById('uploadfiles').onclick = function() {
uploader.start();
return false;
};
},
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
});
},
UploadProgress: function(up, file) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
},
Error: function(up, err) {
document.getElementById('console').appendChild(document.createTextNode("\nError #" + err.code + ": " + err.message));
}
}
});
uploader.init();