Solved

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

Posted on 2016-10-24
12
114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
12 Comments
 
LVL 33

Assisted Solution

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

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

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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 57

Assisted Solution

by:Julian Hansen
Julian Hansen earned 350 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 33

Assisted Solution

by:Big Monty
Big Monty earned 150 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 33

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 57

Accepted Solution

by:
Julian Hansen earned 350 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
 

Author Comment

by:Eduardo Fuerte
ID: 41858880
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 how to dynamically set the form action using jQuery.

751 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