Home > Backend Development > PHP Tutorial > Getting Started with PHP - Summary of Form Processing Issues_PHP Tutorial

Getting Started with PHP - Summary of Form Processing Issues_PHP Tutorial

WBOY
Release: 2016-07-13 10:02:30
Original
1012 people have browsed it

Getting Started with PHP - Summary of Form Processing Issues

After studying these days, there are too many similarities between PHP and C/C. So it seems that there is no problem in getting started simply. However, because I chose a quick-start book, it is inevitable that there will be some The knowledge points are relatively rough. For example, the following two questions made me suffer a bit.

1. The file tag of the form cannot obtain the file name.

I learned about the form in books

Please enter your personal information

Name:
Student ID:
Email:
Password:
Confirm password:
Avatar:

By collecting information, I found that many students also encountered the same problem. Maybe they were reading the same book as me. But I finally found the reason after some hard work. It turned out that by default, html only supports File transfer in text/html format. The form requires multi-format support. So the solution is to add the attribute enctype=multipart/form-data to the form. OK problem solved.

The content of my register.php is as follows:

<!--?php
header(Content-Type:text/html;charset=utf-8);
echo user info is as follow: <br-->;
echo name is .$_POST[username].
;
echo number is .$_POST[id].
;
echo mail is .$_POST[mail].
;
echo password is .$_POST[password].
;
print_r($_FILES);
?>
Copy after login
Upload a file and test it:

The input interface is as follows. I wrote some information. Because it is a character interface, I wrote the avatar part by hand.

The output interface is as follows. You can see that the file has information. Name represents the file name on the client side, type represents the file type. tmp_name represents the temporary file name on the server side

2. The image tag of the form does not display the image.

I also encountered this problem when I was in college and solved it at that time. But so many years have passed and I still can’t remember it. But luckily, after trying it a few times, I remembered the solution again.

Initially, the path I specified was my other directory. So the picture could not be displayed. Later, I placed the picture in the root directory where apache works, which is the /var/www/html directory, and it can be displayed normally. Think about it Also, if files from anywhere can be displayed, why does apache need us to configure ROOT_DIRECTORY?

3. PHP garbled problem

We know that in the HTML page, the encoding problem is specified by specifying http-equiv through the meta tag. But after jumping to the PHP page, this tag is invalid. PHP becomes garbled again. What should I do? It must be There must be a ready-made function that can be used. So I checked online, and sure enough.

Add header(Content-Type=text/html;charset=utf-8) at the beginning of the PHP file; problem solved.

ok. These are some of the problems I have encountered in learning PHP these days. To summarize, especially the first problem, it took me a long time to find a reasonable explanation. I will continue to deepen my understanding in the next few days. Try to write something small this week.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/970255.htmlTechArticleGetting Started with PHP - Summary of Form Processing Problems After Studying in the Past few Days. There are too many similarities between PHP and C/C So the simple introduction now seems to be no problem. But because I chose a book...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template