10 days Learn PHP Day 10

web front end five thousand and thirty-four 13 years ago (2011-04-08)

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
  1. $f = $HTTP_ POST_ FILES [ 'file' ];   
  2.   
  3. $dest_ dir = 'uploads' ; //Set upload directory   
  4.   
  5. $dest = $dest_ dir . '/' . date ( "ymd" ). "_" . $f [ 'name' ]; //I set the file name as date and file name to avoid repetition   
  6.   
  7. $r =move_ uploaded_ file( $f [ 'tmp_ name' ], $dest );   
  8.   
  9. chmod ( $dest , 0755); //Set the properties of the uploaded file   

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.

    ASP,PHP,ASP. NET entry can take ten days, but mastery is by no means ten days. You need to study it yourself.