Jump to content

attachments on forms


mh5445
 Share

Recommended Posts

I have used this helpful page to successfully store temporary files on my server (which i duno how to access): http://www.w3schools.com/php/php_file_upload.aspBut, here are my two questions:1. Can, in the echo part or any other way, have the file sent to an email address (not using sql i dont know how to do that)2. for the restrictions on file type i see the jpeg, gif as image/jpeg. How do I do it if I want to restrict it to videos too- video/mp4 ? that didnt workThanks for any and all help!

Link to comment
Share on other sites

It's easiest to use the extension instead of the mime type. You can get the extension from a filename like this:$extension = array_pop(explode('.', $filename));And then you can check if the extension is jpg, gif, mpg, whatever.Attaching a file is easiest if you use the pear package, but you don't necessarily need to. An email with an attachment is called a multi-part mime message. You can see the general PHP mail reference here:http://www.php.net/manual/en/function.mail.phpThis is an article about sending mult-part mime messages, if you scroll down to the multi-part section you can see a description about how the email needs to be formatted:http://www.zend.com/zend/spotlight/sendmimeemailpart1.phpYou can also use the pear package to take care of all of that for you if the server supports it:http://pear.php.net/package/Mail_Mime

Link to comment
Share on other sites

For what you said about the extension, is that for viewing extensions or restricting it to certain extensions? I am using this type of thing:if ((($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")to restrict to certaipn image formats. If I want to allow more image formats, I simply add another line to the above. If i want to allow mor formats, but want to allow some video formats too, how would i add that line? Like this?:|| ($_FILES["file"]["type"] == "video/mpg") that doesnt seem to work for me...If that is even possible tell me. And if you were trying to show me what I was looking for, I apologize, I am new to php.As for emailing uploaded file, could somone please give me a detailed process of how to do one of those (I am not so sure about what pear or whatever is). I would appreciate it thank.PS Thansk for the help, Im just not that familiar with what you wrote! sry!

Link to comment
Share on other sites

1. Did you find that mime type somewhere or just take a guess at it? My research says it would be video/mpeg NOT mpg. But mime types are sneaky . . .2. JSG was suggesting you revise your test to something like this:if( array_pop(explode('.', $filename)) == "mpg") { # GOOD TO GO}That way you don't need to know the mime type, just the file extension. And, yes, you can add that to your list of OR clauses.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...