Home >Backend Development >PHP Tutorial >Learn PHP in Ten Days - Day 10_PHP Tutorial

Learn PHP in Ten Days - Day 10_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 16:08:09924browse

Learning purpose: Learn to use PHP to upload files and send emails

The upload file form must add enctype="multipart/form-data"
and
Look at the code below:

$f=&$HTTP_POST_FILES['file'];
$dest_dir='uploads';//Set the upload directory
$ dest=$dest_dir.'/'.date("ymd")."_".$f['name'];//I set the file name here with the date plus the file name to avoid duplication
$r=move_uploaded_file ($f['tmp_name'],$dest);
chmod($dest, 0755);//Set the attributes of the uploaded file

The name of the uploaded file is date("ymd") ."_".$f['name'] can be used when inserting into the database later. PHP actually moves the file you uploaded 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 even simpler. You can use the mail() function

mail("recipient address" ,"Subject","Text","From: sender rnReply-to: sender's address");

However, mail() requires server support, and SMTP server needs to be configured under WINDOWS , Generally speaking, any external LINUX space will work.
It seems that uploading files and sending emails is much simpler than ASP. You only need to call functions. ASP also needs to use different components of the server such as FSO, JMAIL and so on.

That’s it for learning PHP in ten days. My three major series of articles all use “Learning in Ten Days” as their names. What I want to tell you is that getting started with ASP, PHP, and ASP.NET can all take ten days. But mastery is by no means ten days, and everyone still needs to study it by themselves.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314895.htmlTechArticleLearning purpose: Learn to use PHP to upload files and send emails. The upload file form must add enctype="multipart/form- data" and input type="file" name="file" Let's take a look at the code: $f= $des...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn