Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Could you point a jQuery/ javascript plugin that possibilites multiple files uploads?

Posted on 2016-10-24
12
Medium Priority
?
129 Views
Last Modified: 2016-10-25
Hi Experts

Could you point a jQuery/ javascript plugin that possibilites multiple files uploads?

This code I'm using by now permits just one file could be uploaded each time.

<!-- Anexo -->
<hr>
<div class='row'>
	<div class="col-xs-12 mb20">
		<label for="anexo_e" class="field-label text-muted mb10">Anexo</label>
		<input name="fileuser" id="fileuser" type="file" class="form-control gui-input br-light light" placeholder="">
	</div>
</div>

<script type="text/javascript">
	$(function () {
		$('#fileupload').fileupload({
			dataType: 'json',
			done: function (e, data) {
				$.each(data.result.files, function (index, file) {
					$('<p/>').text(file.name).appendTo(document.body);
				});
			}
		});
	});
</script>

Open in new window


Thanks in advance.
0
Comment
Question by:Eduardo Fuerte
  • 6
  • 3
  • 3
12 Comments
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 600 total points
ID: 41857334
I've used DropZone in a few projects and love the flexibility of it:

http://www.dropzonejs.com/
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 41857460
Dropzone is probably the one to go for - there is also BlueImp https://github.com/blueimp/jQuery-File-Upload

I have used both - I found DropZone a bit easier to use but that might be because I tried BlueImp some time ago and was still unfamiliar with coding AJAX file uploads.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41858519
Hi

Could you check?

Using dropzone what I did is:

View:
<form action="/file-upload" class="dropzone">
	<div class="fallback">
		 <input name="file" type="file" multiple />
	</div>
</form>

Open in new window


js code:
<script src= <?php  base_url() . 'public/vendor/plugins/dropzone/dropzone.js' ?> >
    var Dropzone = require("dropzone");
</script>

Open in new window


Aparently I could select 03 files to upload in this case:
img001
img002
My doubt is where is the files uploaded?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 60

Assisted Solution

by:Julian Hansen
Julian Hansen earned 1400 total points
ID: 41858565
<form action="/file-upload" class="dropzone">

Open in new window

It will be sent to the url that the action attribute is pointing to.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41858604
In my case:

img003
Where "anexo" is the folder the files must to be uploaded, view is where the Codeigniter index.php remains.

Is it coherent to code this way?
<form action="../../public/uploads/anexos" class="dropzone"  id="my-dropzone">
	<div class="fallback">
		 <input name="file" type="file" multiple />
	</div>
</form>

Open in new window

0
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 600 total points
ID: 41858610
yes you can do that, you can point it to wherever your page is that processes that files and places them accordingly. DZ will supply the mechanism to upload the files, you still need code to accept and process them.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41858629
So, I simplificate just to test and create a folder _anexo under views:
img004
<form action="_anexos" class="dropzone"  id="my-dropzone">
	<div class="fallback">
		 <input name="file" type="file" multiple />
	</div>
</form>

Open in new window


The files weren't saved at this folder.
Is something else necessary in terms of javascript?
0
 
LVL 34

Expert Comment

by:Big Monty
ID: 41858633
you need to write the server side code that'll save the files for you.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41858673
I don't know if this make sense:

<form action="<?php print base_url() . '/public/uploads/anexos'; ?>" class="dropzone"  id="my-dropzone">
	<div class="fallback">
		 <input name="file" type="file" multiple />
	</div>
</form>

Open in new window



I see it elsewhere and don't know it's what you are meaning:

Javascript code for the index.php
var baseurl = "<?php print base_url(); ?>";

Dropzone.options.myAwesomeDropzone = {
url:  baseurl . '/application/controllers/'. upload.php,
previewsContainer: ".dropzone-previews",
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100
}

Open in new window


That calls this:

<?php
	$upload_dir = 'uploads';
	if (!empty($_FILES)) {
		$tempFile = $_FILES['file']['tmp_name']; //this is temporary server location

		// using DIRECTORY_SEPARATOR constant is a good practice, it makes your code portable.
		$uploadPath = dirname(__file__) . DIRECTORY_SEPARATOR . $upload_dir .
			DIRECTORY_SEPARATOR;

		// Adding timestamp with image's name so that files with same name can be uploaded easily.
		$mainFile = $uploadPath . time() . '-' . $_FILES['file']['name'];

		move_uploaded_file($tempFile, $mainFile);
}
?>

Open in new window


(I have to save the updated files' names in database, maybe it could be call a Codeigniter model from here to save it)

Could you check and possibly give orientation?
0
 
LVL 60

Accepted Solution

by:
Julian Hansen earned 1400 total points
ID: 41858701
You are on the right track. You might want to do some sanity checks on the file - what you don't want is someone uploading a malicious file that they can then run on the server.

Use finfo_file to get the Mime Type.

The above code would also be where you would write the data to a database.
0
 

Author Closing Comment

by:Eduardo Fuerte
ID: 41858851
Thanks for the assistance

I feel I need to continue this question with another concerning PHP/ Dropzone.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question