Cloudski
07-08-2002, 01:59 AM
Alright, I figured PHP enough to do a little working :D
Now, how do you upload a file to send to an e-mail as an attachment? Also, I need to make sure it is a proper extension.. ex:(only .txt or .zip)
Thanks in advance to ALL replies
:thumbsup:
Cloudski
07-08-2002, 02:00 AM
:mad: :mad: :mad: Damn frown face lol... I meant to put ex: (.txt or .zip) without a frown being there!!!
Mouldy_Goat
07-08-2002, 12:06 PM
Hi cloudski,
Uploading files in PHP is relatively simple... take a look at this (http://www.php.net/manual/en/features.file-upload.php) page for more info on it.
About checking the extension, the best thing to do would be to check the mime-type of the file instead i.e. by looking at the variable $HTTP_POST_FILES['userfile']['type'] (where userfile is the <input type="file"> element name).
As for sending as an email attachment - this is very fiddly unless you know what you're doing - it's probably worth trying to find a class for PHP which can handle this for you.. like the one here (http://www.phpwizard.net/resources/phpMisc/scripts/pretty/mail.php3).
Hope that helps a bit.
Cloudski
07-08-2002, 12:33 PM
Wow.. thanks Goat.. as for the making the upload.. That tutorial confused me when I looked at it before... Sheesh... I will look at it again...
And the mail script you provided a link to, do you need to edit it in any way, or do you just add it to the page?
Thanks for all your help!:D
Mouldy_Goat
07-08-2002, 02:46 PM
The script's got a little synopsis like this:
$attachment = fread(fopen("test.jpg", "r"), filesize("test.jpg"));
$mail = new mime_mail();
$mail->from = "foo@bar.com";
$mail->headers = "Errors-To: foo@bar.com";
$mail->to = "bar@foo.com";
$mail->subject = "Testing...";
$mail->body = "This is just a test.";
$mail->add_attachment("$attachment", "test.jpg", "image/jpeg");
$mail->send();
What I'd do would be to copy the code and put it all in a file called mail.inc or something and put:
include("mail.inc");
At the top of any script I've want to use it in.
There's no need to edit the script source in any way though... once you've got the file uploaded it should all work fine.
Cloudski
07-08-2002, 05:59 PM
Well, I tested it by simply putting the fields at the top of a php file, and they worked.. sort of... It tries to put the text of a message as an attachment itself.. losing the body's text in the process... Anyways, if I do your include('mail.inc'); Will I still be able to use variables for the From field, etc......
It looks like it would be simple to add more fields to the class... for like a form input.
Sorry I am asking so much, I am just not quite.. good.... with PHP...:(
Thanks again for ALL your help! :D
Cloudski
07-08-2002, 09:32 PM
:rolleyes: You know what? I found out ewhy I could not get an upload script to work..... THE SERVER DOES NOT ALLOW FILE UPLOADS VIA PHP! *sigh* Oh well... it is off to look for a server that hosts php and file uploads just for a couplde of freaking pages....