don
don

Reputation: 4542

DragNDrop and then handle file with PHP to show in a new page

I have a form that allows users to upload a file through the "traditional" input file form element.

Submitting the form to $_SERVER["PHP_SELF"] reloads the page and the if ($_POST['submit']) conditions triggers a function that processes the file and builds a table that shows all the contents of the file.

Now I would like to add to the mix the possibility to drag and drop the file. Unfortunately, all the solutions I have come across rely on the XMLHttpRequest object, which does not permit me to show anything with js (I don't want to get back with Ajax the data to show, simply because I would need to rewrite a really long function).

Any idea on how I could implement the drag and drop without radically changing the way things work?

Upvotes: 0

Views: 43

Answers (1)

Dan Cowell
Dan Cowell

Reputation: 11

If your user only needs to upload a single file you could trigger the submit event on the form manually when a drop event is triggered.

$("#formid").submit();

That's really the only way to do it that I'm aware of - and it falls over when there is the requirement to process multiple files.

How big are the files? If they're small enough you could output the details of the uploaded file in the drop container during the if($_POST['submit']) block, you'd just need to keep track of all previously uploaded files so that you can keep adding to the list.

Upvotes: 1

Related Questions