uploading files using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
srinadhv9
Forum Newbie
Posts: 1
Joined: Mon Apr 09, 2007 12:58 am

uploading files using php

Post by srinadhv9 »

can any one send me the code for uploading files using PHP........
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

There is sample code in the php manual available at php.net
tyrohansen
Forum Newbie
Posts: 8
Joined: Fri Apr 06, 2007 3:57 am

Post by tyrohansen »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


u can use this   also

Code: Select all

<?php

        $to = "tyrohansen@yahoo.com,";
        $from = "<webmaster@ventug.com>";
        $subject = "Here is your attachment";

        $fileatt = $HTTP_POST_FILES["userfile"]["tmp_name"];
        $fileatttype = $HTTP_POST_FILES["userfile"]["type"];
        $fileattname = $HTTP_POST_FILES["userfile"]["name"];

        $file = fopen( $fileatt, 'rb' );
        $data = fread( $file, filesize( $fileatt ) );
        fclose( $file );
        $headers = "From: $from";

       //encoding
        $semi_rand = md5( time() );
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

        $headers .= "\nMIME-Version: 1.0\n" .
                    "Content-Type: multipart/mixed;\n" .
                    " boundary=\"{$mime_boundary}\"";

        $message = "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" .
                $message . "\n\n";

        $data = chunk_split( base64_encode( $data ) );

        $message .= "--{$mime_boundary}\n" .
                 "Content-Type: {$fileatttype};\n" .
                 " name=\"{$fileattname}\"\n" .
                 "Content-Disposition: attachment;\n" .
                 " filename=\"{$fileattname}\"\n" .
                 "Content-Transfer-Encoding: base64\n\n" .
                 $data . "\n\n" .
                 "--{$mime_boundary}--\n";

                      //sending email
                   if( mail( $to, $subject, $message, $headers ) ) {

            echo "<p>The email was sent.</p>";

        }
        else {

            echo "<p>There was an error sending the file.</p> <br>$fileattname";

        }

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply