Solved

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

Posted on 2016-10-24
12
119 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 58

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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 58

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 58

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

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

635 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