HTML / PHP / JS选择多个文件并通过FTP上传 [英] HTML/PHP/JS Select multiple file and upload via FTP

查看:282
本文介绍了HTML / PHP / JS选择多个文件并通过FTP上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy,我需要将一系列文件上传到服务器(在特定的一组图像中)。
我需要一个文件输入来选择多个文件(也是在IE中),我没有权限直接用PHP写在服务器上(权限是775,但FTP和apache用户分成2个不同的组),所以我需要使用FTP连接(我已经可以用一个文件来完成)。
如果有人这么做,有人可以给我建议吗?
在此先感谢

Michele

编辑:我试图使用uploadify,因为Nick建议。

 < script type =text / javascript> 
$(document).ready(function(){
$('#file_upload')。uploadify({
'uploader':'JS / uploadify.swf',
'script':'upload.php',
'cancelImg':'JS / cancel.png',
'文件夹':'TEST / UPLOADS',
'auto':true,
'multiple':true,
'removeCompleted':false,
'queueSizeLimit':3,
'queueID':'queue',$ b $'simUploadLimit': 1
);
});
< / script>

我尝试将ftp连接和ftp_put放入upload.php中,这是正确的?
如果我尝试添加'scriptData'参数,它不能通过文档建议的$ _POST []访问,为什么?



这里是我的测试链接: 测试



测试显示文件已上传但没有文件在服务器的文件夹中。



这里是我的upload.php代码:

  if(!empty($ _ FILES)){
$ tempFile = $ _FILES ['Filedata'] ['tmp_name']; // 1

// $ targetPath = $ _SERVER ['DOCUMENT_ROOT']。 $ _REQUEST ['folder']。 /; // 2
// $ targetFile = str_replace('//','/',$ targetPath)。 $ _FILES [ Filedata上] [名]; // 3


$ ftp_server =***; // ftp服务器的地址。
$ ftp_user_name =***; //用户名
$ ftp_user_pass =***; // Password
$ conn_id = ftp_connect($ ftp_server);
ftp_login($ conn_id,$ ftp_user_name,$ ftp_user_pass);
ftp_pasv($ conn_id,true);

if(ftp_fput($ conn_id,'TEST /'。$ _FILES ['Filedata'] ['name'],$ tempFile,FTP_BINARY)){// $ 4
echo true;
} else {
echo false;
}

ftp_close($ conn_id);
} else {
echo false;
}


解决方案

我通常使用 uploadify
这些文件相当不错,而且使用非常简单。



您需要使用类似的东西来保持连接打开并发送文件而不重新加载页面。



编辑:



您的代码应该是这样的:

  < script type =text / javascript> 
$(函数(){
$('#custom_file_upload')。uploadify({$ b $'uploader':'JS / uploadify.swf',
'script':' JS / uploadify.php',
'cancelImage':'JS / uploadify-cancel.png',
'multi':true,
'auto':true,
' fileTypeExts':'* .jpg',
'fileTypeDesc':'图像文件(.JPG)',
'queueID':'custom-queue',$ b $'queueSizeLimit':3,
'simUploadLimit':3,
'sizeLimit':10240000,
'removeCompleted':false,$ b $'onDialogClose':function(queue){
$(' ');
},
'onQueueComplete':function(stats){
$($ queue $'$' '#status-message')。text(stats.successful_uploads +'上传文件,'+ stats.upload_errors +'错误。');
}
});
});
< / script>

swf 更改为上传者上传者更改为脚本


Hy, I need to upload a series of files to a server (in specific a set of images). I need a single file input to select multiple files (also in IE), I have no permission to write directly with PHP on the server (permission are 775 but FTP and apache users are into 2 different groups) so I need to use an FTP connection (I'm already able to do this with a single file). Can someone advice me if there is someway to do this? Thanks in advance

Michele

Edit: I'm trying to use uploadify as Nick suggested.

 <script type="text/javascript">
    $(document).ready(function() {
        $('#file_upload').uploadify({
            'uploader'  : 'JS/uploadify.swf',
            'script'    : 'upload.php',
            'cancelImg' : 'JS/cancel.png',
            'folder'    : 'TEST/UPLOADS',
            'auto'      : true,
            'multiple'  : true,
            'removeCompleted' : false,
            'queueSizeLimit' : 3,
            'queueID' : 'queue',
            'simUploadLimit' : 1
         );
    });
</script>

I tried to put ftp connection and ftp_put into upload.php it is right?? If I try to add the 'scriptData' parameter it cannot be accessible by $_POST[] as suggested by documentation, why?

here my test link: test

The test shows that files get uploaded but no files in the server's folder.

here is my upload.php code:

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];                          // 1

    //$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';  // 2
    //$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; // 3


    $ftp_server = "***";  //address of ftp server.
    $ftp_user_name = "***"; // Username
    $ftp_user_pass = "***";   // Password
    $conn_id = ftp_connect($ftp_server);
    ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
    ftp_pasv ( $conn_id, true );

    if( ftp_fput($conn_id, 'TEST/' . $_FILES['Filedata']['name'], $tempFile, FTP_BINARY)){                       // 4
        echo true;
    }else{
        echo false;
    }

    ftp_close($conn_id);
} else {
    echo false;
}

解决方案

To allow the upload of multiple files I usually use uploadify It's documentation is fairly good, and it's pretty simple to use.

You need to use something like this in order to keep the connection open and send the files without reloading the page.

EDIT:

Your code should be something like this:

<script type="text/javascript">
$(function() {
    $('#custom_file_upload').uploadify({
        'uploader'       : 'JS/uploadify.swf',
        'script'         : 'JS/uploadify.php',
        'cancelImage'      : 'JS/uploadify-cancel.png',
        'multi'          : true,
        'auto'           : true,
        'fileTypeExts'        : '*.jpg',
        'fileTypeDesc'       : 'Image Files (.JPG)',
        'queueID'        : 'custom-queue',
        'queueSizeLimit' : 3,
        'simUploadLimit' : 3,
        'sizeLimit'   : 10240000,
        'removeCompleted': false,
        'onDialogClose'   : function(queue) {
            $('#status-message').text(queue.filesQueued + ' files have been added to the queue.');
        },
        'onQueueComplete'  : function(stats) {
            $('#status-message').text(stats.successful_uploads + ' files uploaded, ' + stats.upload_errors + ' errors.');
        }
    });             
});
</script>

swf changed to uploader and uploader changed to script.

这篇关于HTML / PHP / JS选择多个文件并通过FTP上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆