multiple file upload problem

Reply

Join Date: Apr 2008
Posts: 78
Reputation: shadiadiph is an unknown quantity at this point 
Solved Threads: 0
shadiadiph shadiadiph is offline Offline
Junior Poster in Training

multiple file upload problem

 
0
  #1
Feb 16th, 2009
Hi I am having a problem can't seem to get my script working it was working fine with just one file before without the for and $x statements I have added can anyone see why it isn't working please ?

html
  1. <form name="iapply3" method="post" action="ionline4.php">
  2. <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
  3. <tr><td colspan="2" class="head">PHOTO </td></tr>
  4. <tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>
  5.  
  6. <tr><td colspan="2" class="head">PHOTO</td></tr>
  7. <tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>




php
  1. $fileatt = $_FILES['fileatt']['tmp_name'];
  2. $fileatt_type = $_FILES['fileatt']['type'];
  3. $fileatt_name = $_FILES['fileatt']['name'];
  4.  
  5.  
  6. $to = 'info@apa.com';
  7. $boundary = '==Multipart_Boundary_x' .md5(time()). 'x';
  8. // headers
  9. $headers .= "From: APA <noreply@apa.com>\n";
  10. $headers .= "MIME-Version: 1.0\n";
  11. $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n";
  12. // message
  13. $message = "--{$boundary}\n";
  14. $message .= "Content-Type: text/html; charset=iso-8859-1\n";
  15. $message .= "Content-Transfer-Encoding: 7bit\n\n";
  16. $message .= "<html>
  17.  
  18. <head>
  19. <title>HTML message</title>
  20.  
  21. </head>
  22. <body>
  23. hello
  24. if(is_uploaded_file($fileatt)){
  25. for($x=0;$x<count($fileatt);$x++)
  26. {
  27.  
  28. $fp = fopen($fileatt[$x], 'rb');
  29. $data = fread($fp, filesize($fileatt[$x]));
  30. fclose($fp);
  31. $data = chunk_split(base64_encode($data));
  32. $message .= "--{$boundary}\n";
  33. $message .= "Content-Type: $fileatt_type[$x];\n name=\"$fileatt_name[$x]\"\n";
  34. //$message .= "Content-Disposition: attachment;\n filename=\"$fileatt_name[$x]\"\n";
  35. $message .= "Content-Transfer-Encoding: base64;\n\n$data\n\n";
  36. $message .= "--{$boundary}--\n";
  37. }
  38. }
  39.  
  40. mail($to, $subject, $message, $headers);
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: multiple file upload problem

 
0
  #2
Feb 16th, 2009
I can't see how this would work even with one file; there are no PHP tags! Furthermore, can you describe what doesn't work when you input two files? Actual PHP errors, or it doesn't add one/both to the message?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 78
Reputation: shadiadiph is an unknown quantity at this point 
Solved Threads: 0
shadiadiph shadiadiph is offline Offline
Junior Poster in Training

Re: multiple file upload problem

 
0
  #3
Feb 16th, 2009
of course the php page already has <?php ?> tags and before you ask the html page also has <php> <html> and <body> tags lol

And it doesn't work sends the email fine but doesn't attch the files?
Last edited by shadiadiph; Feb 16th, 2009 at 11:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: multiple file upload problem

 
0
  #4
Feb 17th, 2009
You are adding two boundaries for each file. Move your second boundary addition outside of the loop.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 78
Reputation: shadiadiph is an unknown quantity at this point 
Solved Threads: 0
shadiadiph shadiadiph is offline Offline
Junior Poster in Training

Re: multiple file upload problem

 
0
  #5
Feb 17th, 2009
mm tried that didn't work thanks for the suggestion though
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 78
Reputation: shadiadiph is an unknown quantity at this point 
Solved Threads: 0
shadiadiph shadiadiph is offline Offline
Junior Poster in Training

Re: almost working

 
0
  #6
Feb 17th, 2009
almost have it working now but its only emailing one file?

  1.  
  2. foreach ($_FILES["fileatt"]["error"] as $key => $error) {
  3. if ($error == UPLOAD_ERR_OK) {
  4. $fileatt = $_FILES['fileatt']['tmp_name'][$key];
  5. $fileatt_type = $_FILES['fileatt']['type'][$key];
  6. $fileatt_name = $_FILES['fileatt']['name'][$key];
  7.  
  8.  
  9. // attachment
  10. $fp = fopen($fileatt, 'rb');
  11. $data = fread($fp, filesize($fileatt));
  12. fclose($fp);
  13.  
  14. $data = chunk_split(base64_encode($data));
  15. $message .= "--{$boundary}\n";
  16. $message .= "Content-Type: $fileatt_type;\n name=\"$fileatt_name\"\n";
  17. //$message .= "Content-Disposition: attachment;\n filename=\"$fileatt_name\"\n";
  18. $message .= "Content-Transfer-Encoding: base64;\n\n$data\n\n";
  19. //$message .= "--{$boundary}--\n";
  20.  
  21.  
  22. }
  23. }
  24.  
  25.  
  26. mail($to, $subject, $message, $headers);
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 78
Reputation: shadiadiph is an unknown quantity at this point 
Solved Threads: 0
shadiadiph shadiadiph is offline Offline
Junior Poster in Training

Re: multiple file upload problem

 
0
  #7
Feb 17th, 2009
i am close to saying EUREKA but unfortunately not. now it sends both the attachments they have the correct file names types in the email but they are all unreadable? jpg gif pdf .doc .txt the .txt file did open though and had this in it
  1. Content-Disposition: attachment; filename="/tmp/phpS6Wyy3"

and nothing else

here is the code i am using

  1. <?
  2. session_start();
  3. error_reporting(apa);
  4. error_reporting(7);
  5. include("../secure/global/connection.php");
  6.  
  7.  
  8. $to = 'info@website.com';
  9. $boundary = '==Multipart_Boundary_x' .md5(time()). 'x';
  10. // headers
  11. $headers .= "From: Website name <noreply@website.com>\n";
  12. $headers .= "MIME-Version: 1.0\n";
  13. $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n";
  14. // message
  15. $message = "--{$boundary}\n";
  16. $message .= "Content-Type: text/html; charset=iso-8859-1\n";
  17. $message .= "Content-Transfer-Encoding: 7bit\n\n";
  18. $message .= "<html>
  19. <head>
  20. <title>HTML message</title>
  21.  
  22. </head>
  23. <body>
  24. hello testing
  25.  
  26. </body>
  27. </html>";
  28.  
  29.  
  30.  
  31. foreach ($_FILES["fileatt"]["error"] as $key => $error) {
  32. if ($error == UPLOAD_ERR_OK) {
  33. $fileatt = $_FILES['fileatt']['tmp_name'][$key];
  34. $fileatt_type = $_FILES['fileatt']['type'][$key];
  35. $fileatt_name = $_FILES['fileatt']['name'][$key];
  36.  
  37.  
  38.  
  39. // attachment
  40. $fp = fopen($fileatt, 'rb');
  41. $data = fread($fp, filesize($fileatt));
  42. fclose($fp);
  43.  
  44. $data = chunk_split(base64_encode($data));
  45. $message .= $data . "\n";
  46. $message .= "--{$boundary}\n";
  47. $message .= "Content-Type: application/$fileatt_type; name=\"$fileatt_name\"\n";
  48. $message .= "Content-Transfer-Encoding: 7bit\n\n";
  49. $message .= "Content-Disposition: attachment; filename=\"$fileatt\"\n\n";
  50.  
  51.  
  52.  
  53.  
  54. }
  55. }
  56.  
  57.  
  58. mail($to, $subject, $message, $headers);
  59.  
  60.  
  61. ?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 647 | Replies: 6
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC