Just after some advice really. This is my first time posting on here, so please forgive me if my post isn't up to the required standard.
I have a form for emailing someone and it also allows the option to add file attachments. I have it working so that it will move a single file and email it and add the details to the database.
When I try with multiple files, it will only ever process the last file in the array.
This is what I have in the form
Expand|Select|Wrap|Line Numbers
- <input type="file" name="attachment[]" id="attachment" multiple/>
Expand|Select|Wrap|Line Numbers
- if(is_array($fdata['name']))
- {
- for($i = 0; $i < count($fdata['name']); ++$i)
- {
- $name_of_file = $_FILES['attachment']['name'][$i];
- $file_name = $guid."-".$name_of_file;
- $temp_name = $_FILES['attachment']['tmp_name'][$i];
- $file_type = $_FILES['attachment']['type'][$i];
- $file_size = $_FILES['attachment']['size'][$i];
- }
- }
- else $files[] = $fdata;
If I put the following in the for loop, it will move the files as requested, but will not allow any other processing on it
Expand|Select|Wrap|Line Numbers
- $pics = array(".bmp", ".gif", ".jpg", "jpeg", ".png"); //5
- $docs = array(".doc", "docx", ".odt", ".pdf", ".ppt", "pptx", ".rtf", ".txt", ".xls", "xlsx"); //10
- $misc = array(".csv", ".htm", "html", ".php", ".pkt", ".rar", ".sql", ".xpi", ".zip"); //9
- $base = basename($file_name);
- $extension = substr($base, strlen($base)-4, strlen($base));
- $extension = strtolower($extension);
- if (in_array($extension,$pics))
- {
- $target = "".FILES."/".FUP_PICS."/";
- }
- if (in_array($extension,$docs))
- {
- $target = "".FILES."/".FUP_DOCS."/";
- }
- if (in_array($extension,$misc))
- {
- $target = "".FILES."/".FUP_MISC."/";
- }
- $target = $target.$base;
- $allowed_extensions = array(".bmp", ".csv", ".doc", "docx", ".gif", ".htm", "html", ".jpg", ".JPG", "jpeg", "JPEG", ".odt", ".pdf", ".php", ".pkt", ".png", ".ppt", "pptx", ".rtf", ".sql", ".txt", ".xls", "xlsx", ".zip");
If I wrap it all in the for loop then it will only process the last file in the array.
I am somewhat stuck on the issue now.
I have tried a foreach loop, but it won't get the value of the variable in the file array to use for processing.
I will attach my file so you can see what I have there as it is around 800 lines long.
I'm looking for some pointers as to where I may be going wrong.
Thanks in advance