1
我有一個問題,上傳多個文件到我的ftp服務器,我使用jQuery的多文件擴展名。使用jquery.MultiFile上傳多個文件到FTP服務器
這是與多文件上傳表單(file_upload.php)頁面上的JavaScript代碼:
<script type="text/javascript">
$(function(){ // wait for document to load
$('.remove').MultiFile({
STRING: {
remove: '<img src="images/upload-remove.png" height="16" width="16" alt="x"/>',
denied:'You can't choose file $ext .\nTry again...',
file:'$file',
selected:'Chosen file: $file',
duplicate:'This file is already chosen:\n$file'
}
});
});
</script>
這是HTML表單(file_upload.php):
<form name="uploader" action="file_upload2.php" method="post" enctype="multipart/form-data">
<fieldset>
<label for="file">Upload file:</label>
<br />
<input type="file" class="multi, remove" name="file[]" value="Upload file" />
<input type="submit" value="submit"/>
</fieldset>
</form>
的PHP部分是我不明白的地方。我試着用這個代碼(file_upload2.php)做到這一點:
<?php
if(isset($_POST['submit']))
{
$ftp_config['server'] = 'ftpserver.org'; //ftp host
$ftp_config['username'] = 'ftp_username'; // ftp username
$ftp_config['password'] = 'ftp_password'; // ftp user password
$ftp_config['web_root'] = 'public_html'; //foldername from user home dir.
$fileElementName = 'file[]'; //file field name
$conn_id = ftp_connect($ftp_config['server']);
$ftp_login = ftp_login($conn_id,$ftp_config['username'],$ftp_config['password']);
if(!ftp_put($conn_id,$ftp_config['web_root'].'/'.$_FILES[$fileElementName]['name'],$_FILES[$fileElementName]['tmp_name'],FTP_BINARY)){
$result = " Error occurred. ";
}else{
$result = " File has been uploaded. ";
}
echo $result;
}
?>
謝謝!它適用於foreach循環。 – user1158882 2012-04-06 23:14:38