10 days Learn PHP Day 10

web front end six thousand five hundred and eighty-two 14 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.

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.