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
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); ?>
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.