473,378 Members | 1,397 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,378 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, 456 views)
Jul 21 '14 #1
0 1279

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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.