Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Learning Purpose: Learn to upload files and email in PHP
Upload file form must add Enctype= "Multipart/form-data"
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-t 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, PHP can be 10 days, but proficient in no more than 10 days ah, but also need everyone to study themselves.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.