我在将多个文件上传到我的 ftp 服务器时遇到问题,我正在使用 jQuery 的多文件扩展名。
这是带有上传表单 (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;
}
?>