Download multiple buttons - one page

I am creating a website for a client, and he wants to have many download buttons on one page. When he clicks on the selected files, uploadify uploads the file to the server, and then changes the value of the Image input field to the image path.

The problem is that I can’t find a way to have several download buttons on one page, each of which will individually fill its own β€œImage” div field. And the client will have n number of divs on one page.

enter image description here

Here is my js code:

$(document).ready(function() { $('.file_upload').uploadify({ 'uploader' : 'content/plugins/category_manager/upload/js/uploadify.swf', 'script' : 'content/plugins/category_manager/upload/upload.php', 'cancelImg' : 'content/plugins/category_manager/upload/js/cancel.png', 'folder' : 'content/plugins/category_manager/upload/uploads', 'fileExt' : '*.jpg;*.gif;*.png', 'fileDesc' : 'Image Files', 'auto' : true, 'onComplete' : function(event, ID, fileObj, response, data) { $("input[name=image]").empty(this).val(fileObj.name); } }); }); 
+6
source share
4 answers

This code:

 jQuery(".file_upload").each(function() { jQuery(this).uploadify({ height : 30, swf : '/uploadify/uploadify.swf', uploader : '/script/uploadify/uploadify.php', width : 120 }); }); 

works very well.

It also requires that the identifiers in the .file_upload elements be unique, even if they are not used.

+19
source

Well, instead of calling the uploadify function for the css class, you need to call the uploadify function for a specific identifier, otherwise it will not work.

So you will need:

 $('#upload1').uploadify({ $('#upload2').uploadify(( 

etc....

+2
source

I had the same problem. I think that you will need to do user control for each download instance that you want on your page. An example of my working uploadify control:

  //ascx <style type="text/css"> .hidden { display:none; } </style> <script src="/Uploadify/jquery.uploadify.v2.1.4.js" type="text/javascript"></script> <script src="/Uploadify/jquery.uploadify.v2.1.4.min.js" type="text/javascript"></script> <script src="/Uploadify/swfobject.js" type="text/javascript"></script> <link href="/Uploadify/uploadify.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function () { var obj = document.getElementById('<%= this.fileInput.ClientID %>'); $(obj).uploadify({ 'uploader': '/uploadify/uploadify.swf', 'script': '/_handlers/Upload.ashx', 'cancelImg': '/uploadify/cancel.png', 'auto': true, 'multi': true, 'fileDesc': 'Image Files', 'fileExt': document.getElementById('<%= this.uTypes.ClientID %>').value, 'buttonText': 'Choose Images', 'folder': '/' + document.getElementById('<%= this.fileDest.ClientID %>').value, 'onAllComplete': function (event, queueID, fileObj, response, data) { var btn = document.getElementById('<%= this.uploadButton.ClientID %>').click(); } }); }); </script> <input id="fileInput" name="fileInput" type="file" runat="server" style="display:none" /> <input id="fileDest" name="fileDest" type="text" runat="server" style="display:none"/> <input id="uTypes" name="uTypes" type="text" runat="server" style="display:none"/> <asp:Button ID="uploadButton" runat="server" CssClass="hidden" OnClick="uploadButton_Clicked" CausesValidation="false"/> 

This is the part of the code located behind the control; some of the parameters you see are passed outside

  //Code behind public partial class UploadifyUpload : System.Web.UI.UserControl { private string fileDestination; public string FileDestination { get { return fileDestination; } set { fileDestination = value; } } private string uploadTypes; public string UploadTypes { get { return uploadTypes; } set { uploadTypes = value; } } public event EventHandler UploadButtonClicked; protected void Page_Load(object sender, EventArgs e) { string virtualPath = fileDestination.Replace(Request.PhysicalApplicationPath, "/"); virtualPath = virtualPath.Replace('\\', '/'); this.fileDest.Value = virtualPath; this.uTypes.Value = uploadTypes; } protected void uploadButton_Clicked(object sender, EventArgs e) { if (this.UploadButtonClicked != null) { this.UploadButtonClicked(this, new EventArgs()); } } } 

I create the control this way and pass in a few variables. The file destination and click event are processed in the code of any page using the control.

 <mgmtControls:UploadifyUpload ID="uploadifyUpload" runat="server" UploadTypes="*.jpg;*.png;*.gif;*.bmp;*.jpeg" /> this.uploadifyUpload.UploadButtonClicked += new EventHandler(UploadifyUploadClicked); this.uploadifyUpload.FileDestination = DocumentPath; 

This works fine for me in Firefox, Chrome and IE, this should lead you in the right direction. You might want to add a default boot option if the user does not have flash installed.

Multiple buttons working

+2
source

I'm not sure if the above answers cover add elements that are added dynamically (via AJAX after the page loads). I ran into this problem. Then, while reading " live () " in the jQuery API, I realized that this could be done as follows:

 $(document).ready(function(){ $('.upload_child_photograph').live('uploadifyEvent', function(){ var child_id = $(this).attr('id').replace('upload_child_photograph_', ""); $('#upload_child_photograph_' + child_id).uploadify({ 'auto' : false, 'swf' : 'uploadify.swf', 'uploader' : 'uploadify.php', 'uploadLimit' : 10, 'multi': true, 'fileSizeLimit' : 0 }); }); $(".upload_child_photograph").trigger("uploadifyEvent"); }); 
0
source

Source: https://habr.com/ru/post/906796/


All Articles