简体   繁体   English

在单个页面上使用PHP,AJAX和jQuery的多个上传表单不起作用

[英]Multiple upload forms using PHP, AJAX and jQuery on single page doesn't work

Does anyone know of a jQuery-AJAX image uploader, where I can have multiple instances of the form on the same page? 有谁知道一个jQuery-AJAX图片上传器,在同一页面上可以有多个表单实例

Let me elaborate on my situation! 让我详细说明我的情况! I have a front end page, where a user can change his profile, when the page loads, it loops through all the content-type rows in the database. 我有一个前端页面,用户可以在其中更改其个人资料,当页面加载时,它会遍历数据库中的所有内容类型行。

I need to apply an image upload form for every type of img . 我需要为每种img类型应用一个图像上传表单。

The problem is, that every plugin I have tried will only allow me to have 1 upload form per page , but I need one for user profile image, one for signature image one for ... as defined by the content elements in the table. 问题是,我尝试过的每个插件仅允许我每页1个上传表单 ,但是我需要一个用于用户个人资料图像,一个用于签名图像,一个用于...,由表中的内容元素定义。

Example: 例:

<form id='upload' method='post' action='script.php?val=profilepic' enctype='multipart/form-data'>
  <div id='drop'>
     Drop Here
     <a>Browse</a>
     <input type='file' name='upl' multiple />
   </div>
   <input style='visibility:hidden' id='".$var2['id']."' value='page_session_weo' />
   <ul style='display:none'>
     <!-- The file uploads will be shown here -->
   </ul>
</form>

<form id='upload' method='post' action='script.php?val=sigpic' enctype='multipart/form-data'>
   <div id='drop'>
     Drop Here
     <a>Browse</a>
     <input type='file' name='upl' multiple />
   </div>
   <input style='visibility:hidden' id='".$var2['id']."' value='page_session_weo' />
   <ul style='display:none'>
     <!-- The file uploads will be shown here -->
   </ul>
</form>

<form id='upload' method='post' action='script.php?val=homepagepic' enctype='multipart/form-data'>
   <div id='drop'>
     Drop Here
     <a>Browse</a>
     <input type='file' name='upl' multiple />
   </div>
   <input style='visibility:hidden' id='".$var2['id']."' value='page_session_weo' />
   <ul style='display:none'>
     <!-- The file uploads will be shown here -->
   </ul>
</form>

Below is the picture to get better understanding of my problem: 以下是可以更好地理解我的问题的图片:

案件

Any help or advise would be appreciated. 任何帮助或建议,将不胜感激。

Yes, you could! 是的,你可以! I would recommend Uploadify script that works very well. 我建议上载效果很好的Uploadify脚本。 It supports multiple file uploads and multiple instances of the uploader. 它支持多个文件上传和上传器的多个实例。

Example: 例:

$(function() {
    $("#file_upload_1").uploadify({
        height        : 30,
        swf           : '/uploadify/uploadify.swf',
        uploader      : '/uploadify/uploadify.php',
        width         : 120
    });
});

and

$(function() {
    $("#file_upload_2").uploadify({
        height        : 30,
        swf           : '/uploadify/uploadify.swf',
        uploader      : '/uploadify/uploadify.php',
        width         : 120
    });
});

In your case your uploader doesn't work simply because you have multiple ids with the same name on the page. 就您而言,您的上传器无法正常运行,因为您在页面上拥有多个具有相同名称的ID。 It's invalid. 无效 Look at the example about, it represents correct idea that you would have to implement using your code or to use the other script to do it! 看一下有关示例,它代表了正确的想法,您必须使用代码或其他脚本来实现它!

Important: User Ray Nicholus comments below that the iframe "trick" mentioned in this answer only works in IE9. 重要提示:用户Ray Nicholus在下面评论说,此答案中提到的iframe“技巧”仅在IE9中有效。 For all modern browsers, XHR2 (ajax) requests are used to upload the files. 对于所有现代浏览器,XHR2(ajax)请求都用于上传文件。

Not sure if this is what you're looking for: 不知道这是您要找的东西吗?

Multiple file upload plugin with progress-bar, drag-and-drop. 带有进度条,拖放功能的多文件上传插件。

The Widen/fine-uploader AJAX file upload plug-in allows users to upload multiple files without having to refresh the page. Widen / fine-uploader AJAX文件上传插件使用户可以上传多个文件,而无需刷新页面。 In addition, you can use any element to trigger the file selection window. 此外,您可以使用任何元素来触发文件选择窗口。 The plug-in creates a semi-transparent file input screen over the button you specify, so when a user clicks on the button, the normal file selection window is shown. 该插件会在您指定的按钮上方创建一个半透明的文件输入屏幕,因此,当用户单击该按钮时,将显示正常的文件选择窗口。 After the user selects a file, the plug-in submits the form that contains the file input to an iFrame. 用户选择文件后,插件会将包含输入文件的表单提交给iFrame。 So it isn't true AJAX but provides the same user experience. 因此,这不是真正的AJAX,但可以提供相同的用户体验。

It has been turned into a commercial product: fineuploader.com 它已经变成一种商业产品: fineuploader.com

Github project is here Github项目在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM