Hi there I'm trying to set up a script to upload a number of files.
Based on a user specified value (currently hard coded) PHP generates the respective amount of file upload fields :
for($i=0;$i < $number;$i++)
{
echo "Choose a file to upload: <input type=\"file\" name=\"upload$i\" /><br />";
}
Everything works out now but i'm having problems getting the file information like so:
$filename = $_FILES["upload0"]["name"];
$filesize = $_FILES["upload0"]["size"];
$filetype = $_FILES["upload0"]["type"];
$file_tmp = $_FILES["upload0"]["tmp_name"];
$file_err = $_FILES["upload0"]["error"];
Nothing appears.
I've tried
echo "Choose a file to upload: <input type=\"file\" name=\"upload[]\" /><br />";
With the above code, If i have for example 2 input fields I can't get any info about the uploaded files using
foreach($_FILES["upload"] as $a)
Any suggestions? I'm basically trying to loop through all the file information once the upload button is clicked.
The full script is :
<?php
class uploadDiag
{
function __construct($number)
{
if(!isset($_POST['submit']))
{
?>
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<!--form has to have attribute enctype="multipart/form-data" otherwise the file upload will not work. -->
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<!--The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by PHP.-->
<?php
for($i=0;$i < $number;$i++)
{
echo "Choose a file to upload: <input type=\"file\" name=\"upload$i\" /><br />";
}
?>
<input type="submit" value="Upload File" name="submit" />
</form>
<?php
}
else
{
$filename = $_FILES["upload0"]["name"];
$filesize = $_FILES["upload0"]["size"];
$filetype = $_FILES["upload0"]["type"];
$file_tmp = $_FILES["upload0"]["tmp_name"];
$file_err = $_FILES["upload0"]["error"];
printf("File Name is : %s File size is %s",$filename,$filesize);
}
}
}
?>
Thanks in advance 🙂