Jump to content

Dynamic File upload system


baconbeastnz

Recommended Posts

Hi there, I am creating (and thought I had finished) a dynamic upload system. Dynamic in that once you have onChanged() all <input type="file"> fields, 2 more pop up, so you can upload as many files as you want.

 

Each time I pop out 2 more fields, I simply regen the fields again with 2 more and set the innerhtml of a div. Doing this removes the values of the already used fields. My plan was to simply maintain the values of the fields by setting the value="" parameter, however this is not possible, due to the security implications!! GRRR

 

I need a way to keep the used fields unchanged so they retain their values, then just pop on 2 extra ones, any ideas?

Link to comment
https://forums.phpfreaks.com/topic/162955-dynamic-file-upload-system/
Share on other sites

The only way I know of to append without replacing content is to use the DOM API.

 

 

<html>
<title>Dynamic Download Fields</title>
<script language="javascript">
<!--
	function AddSlot(input_element) {
		var c = input_element.parentNode;
		if(c != null) {
			var newFile = document.createElement('input');
			var lineBreak = document.createElement('br');
			newFile.type="file";
			newFile.name="files[]";
			newFile.setAttribute('onchange', "AddSlot(this)");
			c.appendChild(newFile);
			c.appendChild(lineBreak);
			return true;
		}
		return false;
	}
//-->
</script>
</html>
<body>
<form>
	<div id="file_container">
		<input type="file" name="files[]" onchange="AddSlot(this);">
		<br>
	</div>
</form>
</body>
</html>

 

 

For example.

 

 

With AJAX though that's going to get more complex since obviously using a preexisting HTML string complicates things.  I think jQuery can append an HTML string without replacement, or you could change how your AJAX is returned.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.