Link to home
Start Free TrialLog in
Avatar of jd_18286
jd_18286

asked on

Multiple upload one input

Hi, i was wondering if someone cold help me making a demo page of this script im having problems outputting the files in php

http://davidwalsh.name/multiple-file-upload

Open in new window

Avatar of ollyatstithians
ollyatstithians
Flag of United Kingdom of Great Britain and Northern Ireland image

Hmmm.. he didn't quite give away all the info there did he.
Here is a working 1 page demo for you. Note that I have just done a var_dump() at the end so you can see how the $_FILES array is organised.
Needless to say, it isn't valid HTML. There is no attribute "MULTIPLE".
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Multiple file upload demo</title>
		<meta http-equiv="Content-Type" content="text/html">
		<meta http-equiv="Content-Script-Type" content="text/javascript">
		<meta http-equiv="Content-Style-Type" content="text/css">

	</head>
	<body>
	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> 		
		<p><strong>Upload Files:</strong> <input type="file" name="filesToUpload[]" id="filesToUpload" multiple="multiple" onChange="makeFileList();" /><input type="submit" /></p>
	</form>
	<p>
		<strong>Files You Selected:</strong>

	</p>
	<ul id="fileList"><li>No Files Selected</li></ul>
	
	<script type="text/javascript">
		function makeFileList() {
			var input = document.getElementById("filesToUpload");
			var ul = document.getElementById("fileList");
			while (ul.hasChildNodes()) {
				ul.removeChild(ul.firstChild);
			}
			for (var i = 0; i < input.files.length; i++) {
				var li = document.createElement("li");
				li.innerHTML = input.files[i].name;
				ul.appendChild(li);
			}
			if(!ul.hasChildNodes()) {
				var li = document.createElement("li");
				li.innerHTML = 'No Files Selected';
				ul.appendChild(li);
			}
		}
	</script>
	<pre>
<?php
var_dump($_FILES);
?>
	</pre>
	</body>
</html>

Open in new window

What is it exactly your problem with it?. It works
ludwigDiehl,
The code as presented does not work without modification, as there is an error in the php script.
The 'working' example does not actually upload anything. There is not even a form in it.
What does work is a javascript list of the contents of the file control.

I am not trying to slate the original article though. I is an interesting concept, if a little shady from the standards point of view.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial