I have a multipart form in which I allow the user to select multiple files which is placed in an array. Here is a scaled down portion of my code:
<form id="fileupload" action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
</form>
In my upload.php file, I want to write to a text file and place info from each file (doesn't matter how it's formatted, array is fine).
$date = $_POST["date"];
$files = $_POST["files"];
$myFile = $date . ".txt";
$fh = fopen($myFile, 'w') or die("cant_open_file");
$stringData = "Date: " . $date . "\n";
$stringData .= "Uploaded Files:\n";
$stringData .= $file; // prints nothing?
fwrite($fh, $stringData);
fclose($fh);
However, nothing is $file is printing nothing.
Question
How can I print the file info for each file that is chosen from the user into my text file?
Desired output
Date: Todays Date
Files: 2 file(s)
File: someimage1.png
Size: 10KB
File: someimage1.png
Size: 20KB
Update
For some reason, $_FILES['files'] is blank when submitted but I when I use the preceding example, "File: " and "Size: " print out, but $file['name'] and $file['size'] seem to be blank. Also, say I choose 3 files, "File/Size" is printed 5 times (suggesting that 5 files were chosen). This is the same for any amount of files chosen. I've made sure the correct values are in php.ini as well. Not sure where to go from here.
foreach($files as $file){
$stringData .= " File: ".$file['name']."\n"; // return blank
$stringData .= " Size: ".$file['size']."\n"; // return blank
}
Also, I am using jQuery File Upload Demo.