Objective: to use PHP to upload files and send emails to upload files, you must add enctypemultipartform-data and inputtypefilenamefile to view the code: $ f $ HTTP_POST_FILES [file]; $ dest_diruploads; set the upload directory $ dest $ dest_dir .. date (ymd ). _. $ f [name]; here I want to learn how to upload files and send emails using PHP
Enctype = "multipart/form-data" must be added to the file upload form"
And
Let's take a look at the code below:
$ F = & $ HTTP_POST_FILES ['file'];
$ Dest_dir = 'uploads'; // sets the upload directory.
$ Dest = $ dest_dir. '/'. date ("ymd "). "_". $ f ['name']; // Here I set the file name to date plus the file name to avoid duplication.
$ R = move_uploaded_file ($ f ['tmp _ name'], $ dest );
Chmod ($ dest, 0755); // sets the attributes of the uploaded file
The uploaded file name is date ("ymd "). "_". $ f ['name'] can be used later when it is inserted into the database. PHP actually moves the files you uploaded from the temporary directory to the specified directory. Move_uploaded_file ($ f ['tmp _ name'], $ dest );
Mail is simpler. you can use the mail () function.
Mail ("recipient address", "topic", "body", "From: sender \ r \ nReply-to: sender address ");
However, mail () requires the support of the server. in WINDOWS, you also need to configure the SMTP server. Generally, the LINUX space outside will work.
It seems that uploading files and sending emails are much simpler than ASP. you only need to call the function. ASP also needs to use different server components such as FSO and JMAIL.
I have learned PHP for ten days. my three series of articles use "ten days of study" as their names. I want to tell you ASP, PHP, and ASP. NET can be started for ten days, but proficient is by no means ten days. you need to study it on your own.
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.