Page 1 of 1

Uploading multiple files not working...

Posted: Thu Apr 29, 2010 4:54 am
by it2051229
I have set up a 3 "<input type=file name='files[]' />" in my php code since I am wanting to upload three files in a click of one "submit" button. It was working when I browsed 3 pictures or any 3 document files.. BUT, if I upload 3 Mp3 files it doesn't work... I have set the php.ini max file upload to 20 megabytes... the mp3 files I am uploading is around 4 megabytes. But If i upload the mp3 one at a time it does work..... If it does work with document files, why doesn't it work with mp3 files?

Re: Uploading multiple files not working...

Posted: Thu Apr 29, 2010 7:18 am
by social_experiment

Code: Select all

<?php "<input type=file name='files[]' /> ?>
Why do you have it as an array? If you have 3 seperate file input boxes, just use them seperately (files1, files2, files3).
I just thought about something though, the possible downside is that you have to check all 3 file inputs seperately (if you are using it like i suggest).

Code: Select all

<?php
 if (isset($_POST['files1'])) {
  //do all the things to check the file
 }
 
 if (isset($_POST['files2'])) {
  // do all the things to check the file
 }

 if (isset($_POST['files3'])) {
  // do all the things to check the file
 }
?>
Could you please paste the code you are using?

Re: Uploading multiple files not working...

Posted: Thu Apr 29, 2010 7:32 am
by it2051229
actually, I was planning to make it more dynamic that's why i used "files[]" because at a later point, i'm not only limiting myself in uploading 3 files but rather dynamically add more "upload boxes" via javascript...

here's my code...

Code: Select all

<?php
	if(isset($_POST["uploadbutton"]))
	{
		echo "HEEEEEEEEYYY!!!";
		$fileNames = $_FILES["files"]["name"];
		
		echo "This is Test 1 You are uploading ".count($fileNames)." files";
	}
	else if(isset($_POST["uploadbutton2"]))
	{
		echo "HEY!!!!";
		$fileNames = $_FILES["files"]["name"];
		
		echo "This is Test 2 You are uploading ".count($fileNames)." files";
	}
?>
<html>
	<head>
		<script type="text/javascript">
			function addUploadBox()
			{
				var upload = document.getElementById("uploads");
				
				var uploadBox = document.createElement("input");
				uploadBox.setAttribute("type", "file");
				uploadBox.setAttribute("name", "files[]");
				
				upload.appendChild(uploadBox);
			}
		</script>
	</head>
	<body>
		<h1>Test 1.. Uploading using a dynamically added box</h1>
		<input type="button" value="Add an upload box" onclick="addUploadBox()" />
		<form id="uploads" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" enctype="multipart/form-data">
			<input type="submit" name="uploadbutton" value="Upload" />
		</form>
		
		<h2>Test 2.. Uploading using a static box</h2>
		<form id="uploads" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" enctype="multipart/form-data">
			<input type="file" name="files[]" />
			<input type="file" name="files[]" />
			<input type="file" name="files[]" />
			<input type="submit" name="uploadbutton2" value="Upload" />
		</form>
	</body>
</html>