I have a browser form in which items can be checked off for receipt by email. They may be images, PDFs or other file types. When submitted to the cgi app on the server I seem to have it all working with one exception. I can't figure out how to specify the path for the selected files.
I'm using $files = array("fileone.ext","filetwo.ext")
My database is running via cgi.bin so the challenge (for me) is how to insert the path to the files which are in the sub-directories of the root. I know their locations, it's the format in my PHP array that eludes me.
Would it be array("/images/fileone.ext","/docs/filetwo.ext") ?
Attachment Paths
Moderator: General Moderators
-
MichiganJim
- Forum Newbie
- Posts: 3
- Joined: Fri Aug 19, 2011 11:28 am
Re: Attachment Paths
No answers, but I've made some progress...
I'm using the found script below to try to send multiple attachments from a web server. The array of files varies but Im handling that okay. I can't get past a couple of errors though and would appreciate any sharper eyes than mine. The errors appear to be path related and repeat for every attached file; one is posted after the script.
The path in the array works to load the files in a browser when the domain is switched with the DOCUMENT_ROOT.
Warning: fopen(/images/classes/dc2010.jpg): failed to open stream: No such file or directory in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 24
Warning: filesize(): stat failed for /images/classes/dc2010.jpg in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 25
Warning: fread() expects parameter 1 to be resource, boolean given in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 25
Warning: fclose() expects parameter 1 to be resource, boolean given in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 26
I'm using the found script below to try to send multiple attachments from a web server. The array of files varies but Im handling that okay. I can't get past a couple of errors though and would appreciate any sharper eyes than mine. The errors appear to be path related and repeat for every attached file; one is posted after the script.
The path in the array works to load the files in a browser when the domain is switched with the DOCUMENT_ROOT.
Code: Select all
#!/usr/bin/php
<?php
$files = array($_SERVER['DOCUMENT_ROOT'].'/images/classes/dc2010.jpg',$_SERVER['DOCUMENT_ROOT'].'/images/classes/dc2010.jpg');
$to = "me@mydomain.com";
$from = "me@mydomain.com";
$sub ="Testing for multiple attachment";
$msg = "Attachment mail testing";
$headers = "From: $from";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$msg = "This is a multi-part message in MIME format.\n\n" . "–{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $msg . "\n\n";
// attachments code starts
for($x=0;$x<count($files);$x++)
{
$msg .= "–{$mime_boundary}\n";
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
$msg .= "–{$mime_boundary}–\n";
$res = @mail($to, $sub, $msg, $headers);
if($res)
{
echo "<p>mail sent with attachments</p>";
}
else
{
echo "<p>error in processing email!</p>";
}
?>
Warning: filesize(): stat failed for /images/classes/dc2010.jpg in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 25
Warning: fread() expects parameter 1 to be resource, boolean given in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 25
Warning: fclose() expects parameter 1 to be resource, boolean given in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 26