使用jquery.MultiFile将多个文件上载到FTP服务器

时间:2012-04-06 17:39:33

标签: php jquery

我在将多个文件上传到我的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;
}
?>

1 个答案:

答案 0 :(得分:0)

对于上传的每个文件,您必须遍历$_FILES

执行print_r($_FILES);查看您必须使用的内容。