Web Analytics Made Easy -
StatCounter Uploading Stuff - CodingForum


No announcement yet.

Uploading Stuff

  • Filter
  • Time
  • Show
Clear All
new 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
    Damn frown face lol... I meant to put ex: (.txt or .zip) without a frown being there!!!


    • #3
      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
        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
          The script's got a little synopsis like this:

          $attachment = fread(fopen("test.jpg", "r"), filesize("test.jpg"));

          $mail = new mime_mail();
          $mail->from = "[email protected]";
          $mail->headers = "Errors-To: [email protected]";
          $mail->to = "[email protected]";
          $mail->subject = "Testing...";
          $mail->body = "This is just a test.";
          $mail->add_attachment("$attachment", "test.jpg", "image/jpeg");

          What I'd do would be to copy the code and put it all in a file called mail.inc or something and put:


          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
            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
              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....