Learning purpose: learn to upload files and send emails in PHP
Enctype="multipart/form data" must be added to the uploaded file form
And<input type="file" name="file">
Let's take a look at the code:
PHP code
- $f = $HTTP_POST_FILES [ 'file' ];
-
- $dest_dir = 'uploads' ;
-
- $dest = $dest_dir . '/' . date ( "ymd" ). "_" . $f [ 'name' ];
-
- $r =move_uploaded_file( $f [ 'tmp_name' ], $dest );
-
- chmod ( $dest , 0755);
The uploaded file is named date ("ymd"). "_". $f ['name '], which can be inserted into data base PHP actually moves the uploaded files from the temporary directory to the specified directory. move_uploaded_file($f['tmp_name'],$dest); This is the key
As for sending emails, it is easier to use the mail() function
Mail ("recipient address"“ theme "," body "," From: sender rnReply to: sender address ");
But mail() needs The server The SMTP server needs to be configured under Windows. Generally speaking, the external LINUX space is OK.
It seems that uploading files is better than sending emails ASP It is much simpler. Just call the function. ASP also needs to use different components of the server, such as FSO and JMAIL.
It can take ten days to get started with ASP, PHP and ASP.NET, but it is not ten days to master them. You need to study them yourself.