Learning Purpose: Learn to upload files and email in PHP
Upload file form must add Enctype= "Multipart/form-data"
and <input type= "file" name= "file" >
Let's take a look at the code:
$f =& $HTTP _post_files[' file '];
$dest _dir= ' uploads '/set upload directory
$dest = $dest _dir. '/'. Date ("Ymd"). " _ ". $f [' name '];//me here Set file name to date plus filename to avoid duplication
$r =move_uploaded_file ($f [' Tmp_name '], $dest);
chmod ($dest, 0755);//Set the properties of the uploaded file
The uploaded file name is date ("Ymd"). _ ". $f [' name '], which can be used later when inserting into the database, PHP actually moves the file you uploaded from the temporary directory to the specified directory. Move_uploaded_file ($f [' Tmp_name '], $dest); That's the key.
It's easier to send mail, you can use the mail () function
Mail ("Recipient address", "subject", "Body", "From: Sender \r\nreply-to: Sender's address");
However, mail () requires the support of the server, in Windows also need to configure the SMTP server, generally outside the Linux space is OK.
It seems that uploading files and sending emails is much simpler than ASP, as long as you call a function. ASP also needs to use different components of the server such as FSO, JMail and so on.
10 days Learn PHP said here, my three series of articles are used "ten days" as the name, want to tell everyone is asp,php,asp. NET entry can be 10 days, but mastery is by no means 10 days, but also need everyone to study themselves.