473,396 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Uploading multiple files and processing them

Hi all,

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
  1. <input type="file" name="attachment[]" id="attachment" multiple/>
This is what I have in the PHP code for processing the file

Expand|Select|Wrap|Line Numbers
  1. if(is_array($fdata['name']))
  2. {
  3.     for($i = 0; $i < count($fdata['name']); ++$i)
  4.     {
  5.         $name_of_file = $_FILES['attachment']['name'][$i];
  6.         $file_name = $guid."-".$name_of_file;
  7.         $temp_name = $_FILES['attachment']['tmp_name'][$i];
  8.         $file_type = $_FILES['attachment']['type'][$i];
  9.         $file_size = $_FILES['attachment']['size'][$i];
  10.     }
  11. }
  12. else $files[] = $fdata;
  13.  
This will process only the last file.

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
  1. $pics = array(".bmp", ".gif", ".jpg", "jpeg", ".png"); //5
  2. $docs = array(".doc", "docx", ".odt", ".pdf", ".ppt", "pptx", ".rtf", ".txt", ".xls", "xlsx"); //10
  3. $misc = array(".csv", ".htm", "html", ".php", ".pkt", ".rar", ".sql", ".xpi", ".zip"); //9
  4.  
  5. $base = basename($file_name);
  6. $extension = substr($base, strlen($base)-4, strlen($base));
  7. $extension = strtolower($extension);
  8.  
  9. if (in_array($extension,$pics))
  10. {
  11.     $target = "".FILES."/".FUP_PICS."/";
  12. }
  13.  
  14. if (in_array($extension,$docs))
  15. {
  16.     $target = "".FILES."/".FUP_DOCS."/";
  17. }
  18.  
  19. if (in_array($extension,$misc))
  20. {
  21.     $target = "".FILES."/".FUP_MISC."/";
  22. }
  23.  
  24. $target = $target.$base;
  25.  
  26. $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");
  27.  
  28.  
This will then not allow me to access the variables outside the loop so I can further process it (email the file, add the details to the database0.

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
Attached Files
File Type: txt attach.txt (25.2 KB, 457 views)
Jul 21 '14 #1
0 1281

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Spidah | last post by:
Is there a way to select a directory on your local computer and automatically upload all files in to your server?
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
1
by: Sönke Greve | last post by:
Hi there, i want to enable uploading lots of images and later display it as an online gallery. Therefore i need a way of using the FileUpload Component with selecting multiple files or a whole...
0
by: Moskie | last post by:
I have a form where the user is able to provide an arbitrary number of attachments. This is done through Javascript that dynamically generates INPUT fields, each of which has the NAME attribute set...
4
by: suneelbabu | last post by:
Hi, Iam trying to uploading 3 files at a time using <input type=file> i have taken AspUpload.Clsupload class. when i try to save they are not saving. Is it possible to save mulitple files...
6
by: Jankie | last post by:
Hi everybody ! I'd be grateful if anyone can point out to me what is missing to get following code working <?php $filename = $_FILES; $tempname = $_FILES; ------ ------- ?>
4
by: ogo796 | last post by:
hi everyone i have a problem with uploading two files at the at the same time. cause the code below tells me that invalid supply argument forach. destfile = /pathe/to/directory; foreach...
5
by: cmrhema | last post by:
Hi, I am using .net framework 2.0. I want to upload multiple files. Usually the file upload control will upload only one file at a time. Whereas I want to upload more than one file. Any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.