Solved

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

Posted on 2016-10-24
12
111 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 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 55

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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 55

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 55

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 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