Uploading multiple files not working...
Moderator: General Moderators
Uploading multiple files not working...
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?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Uploading multiple files not working...
Code: Select all
<?php "<input type=file name='files[]' /> ?>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
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Uploading multiple files not working...
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...
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>