| | |
multiple file upload problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 78
Reputation:
Solved Threads: 0
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
php
html
PHP Syntax (Toggle Plain Text)
<form name="iapply3" method="post" action="ionline4.php"> <input type="hidden" name="MAX_FILE_SIZE" value="300000" /> <tr><td colspan="2" class="head">PHOTO </td></tr> <tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr> <tr><td colspan="2" class="head">PHOTO</td></tr> <tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>
php
PHP Syntax (Toggle Plain Text)
$fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $to = 'info@apa.com'; $boundary = '==Multipart_Boundary_x' .md5(time()). 'x'; // headers $headers .= "From: APA <noreply@apa.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n"; // message $message = "--{$boundary}\n"; $message .= "Content-Type: text/html; charset=iso-8859-1\n"; $message .= "Content-Transfer-Encoding: 7bit\n\n"; $message .= "<html> <head> <title>HTML message</title> </head> <body> hello if(is_uploaded_file($fileatt)){ for($x=0;$x<count($fileatt);$x++) { $fp = fopen($fileatt[$x], 'rb'); $data = fread($fp, filesize($fileatt[$x])); fclose($fp); $data = chunk_split(base64_encode($data)); $message .= "--{$boundary}\n"; $message .= "Content-Type: $fileatt_type[$x];\n name=\"$fileatt_name[$x]\"\n"; //$message .= "Content-Disposition: attachment;\n filename=\"$fileatt_name[$x]\"\n"; $message .= "Content-Transfer-Encoding: base64;\n\n$data\n\n"; $message .= "--{$boundary}--\n"; } } mail($to, $subject, $message, $headers);
•
•
Join Date: Apr 2008
Posts: 78
Reputation:
Solved Threads: 0
almost have it working now but its only emailing one file?
PHP Syntax (Toggle Plain Text)
foreach ($_FILES["fileatt"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $fileatt = $_FILES['fileatt']['tmp_name'][$key]; $fileatt_type = $_FILES['fileatt']['type'][$key]; $fileatt_name = $_FILES['fileatt']['name'][$key]; // attachment $fp = fopen($fileatt, 'rb'); $data = fread($fp, filesize($fileatt)); fclose($fp); $data = chunk_split(base64_encode($data)); $message .= "--{$boundary}\n"; $message .= "Content-Type: $fileatt_type;\n name=\"$fileatt_name\"\n"; //$message .= "Content-Disposition: attachment;\n filename=\"$fileatt_name\"\n"; $message .= "Content-Transfer-Encoding: base64;\n\n$data\n\n"; //$message .= "--{$boundary}--\n"; } } mail($to, $subject, $message, $headers);
•
•
Join Date: Apr 2008
Posts: 78
Reputation:
Solved Threads: 0
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
and nothing else
here is the code i am using
PHP Syntax (Toggle Plain Text)
Content-Disposition: attachment; filename="/tmp/phpS6Wyy3"
and nothing else
here is the code i am using
PHP Syntax (Toggle Plain Text)
<? session_start(); error_reporting(apa); error_reporting(7); include("../secure/global/connection.php"); $to = 'info@website.com'; $boundary = '==Multipart_Boundary_x' .md5(time()). 'x'; // headers $headers .= "From: Website name <noreply@website.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n"; // message $message = "--{$boundary}\n"; $message .= "Content-Type: text/html; charset=iso-8859-1\n"; $message .= "Content-Transfer-Encoding: 7bit\n\n"; $message .= "<html> <head> <title>HTML message</title> </head> <body> hello testing </body> </html>"; foreach ($_FILES["fileatt"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $fileatt = $_FILES['fileatt']['tmp_name'][$key]; $fileatt_type = $_FILES['fileatt']['type'][$key]; $fileatt_name = $_FILES['fileatt']['name'][$key]; // attachment $fp = fopen($fileatt, 'rb'); $data = fread($fp, filesize($fileatt)); fclose($fp); $data = chunk_split(base64_encode($data)); $message .= $data . "\n"; $message .= "--{$boundary}\n"; $message .= "Content-Type: application/$fileatt_type; name=\"$fileatt_name\"\n"; $message .= "Content-Transfer-Encoding: 7bit\n\n"; $message .= "Content-Disposition: attachment; filename=\"$fileatt\"\n\n"; } } mail($to, $subject, $message, $headers); ?>
![]() |
Similar Threads
- Multiple File(s) upload without Multiple Browse option (ASP.NET)
- Multiple files Upload plz HelP (PHP)
- Upload image folder (PHP)
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- Elegant file upload of multiple files (PHP)
- how to upload multiple files using jsp (JSP)
- Multiple items with the same id problem (edit-in-place) (JavaScript / DHTML / AJAX)
- Synchronizing Multi-Video Player Problem !!! (Java)
- uploading multiple files, 'post' not working off server (works fine off local host) (JSP)
- how the multiple file can be copied and write into the another file (JSP)
Other Threads in the PHP Forum
- Previous Thread: Help on formatted text and images from mysql database
- Next Thread: My WebBot
Views: 647 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php phpvotingscript problem query radio random recursion regex remote script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





