Solved

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

Posted on 2016-10-24
12
93 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 32

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 51

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
 
LVL 51

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 32

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 32

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 51

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
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.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now