Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Uploading Stuff

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Uploading Stuff

    Alright, I figured PHP enough to do a little working

    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.. exonly .txt or .zip)

    Thanks in advance to ALL replies

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Damn frown face lol... I meant to put ex: (.txt or .zip) without a frown being there!!!

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi cloudski,

    Uploading files in PHP is relatively simple... take a look at this 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.

    Hope that helps a bit.

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •