PHP入门-表单处理问题总结
PHP入门-表单处理问题总结
这几天的学习下来.PHP和C/C++有太多的相似之处了.所以简单的入门现在看来已经没有问题了.但是因为选取的是一本快速入门的书籍,难免有些知识点比较粗糙.比如下面两个问题就让我吃了点亏.
1. 表单的文件标签无法获取到文件名.
在书籍里面了解到,表单
请输入您的个人信息
姓名:学号:
邮箱:
密码:
确认密码:
头像:
通过搜集资料,发现很多同学也遇到了相同的问题.可能和我看的是一样的书吧.不过总算是经过一番努力以后找到了原因,原来是因为默认情况下,html仅仅支持text/html格式的文件传输.而表单需要多格式支持.所以解决办法就是.在form中添加属性 enctype=multipart/form-data . ok问题解决.
我的regist.php的内容如下:
<!--?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); ?>
输入界面如下,我写入一些信息,因为是字符界面,所以头像部分是我手写进去的.
输出界面如下.可以看到文件是有信息的.其中name表示在客户端的文件名,type表示文件类型.tmp_name表示在服务器端的临时文件名
2. 表单的图像标签不显示图像.
这个问题在大学的时候也遇到过,当时解决了.但是转眼这么多年过去了.哪里还记得住啊.不过运气号,试了几下就又想起解决办法了.
最初我指定的路径是我其它的目录.所以图片无法显示,后来我把图片放在了apache工作的根目录,即/var/www/html目录下,就可以正常显示了.想想也是,如果哪里的文件都能显示,apache何必还要我们配置工作ROOT_DIRECTORY呢.
3. php乱码问题
我们知道在html页面中,编码问题是通过meta标签指定http-equiv的方式来指定的.但是跳转到php页面以后,这个标签失效了.php又成了乱码.怎么办,想必是一定有现成的函数可以使用的.所以就网上查了一下,果然.
在PHP文件的开头处加入 header(Content-Type=text/html;charset=utf-8);问题解决.
ok.这就是这几天学习PHP遇到的一些的问题.总结一下,尤其是第一个问题,查了很久才找到一个合理的解释.接下来的几天我会继续加深理解,争取本周能够写出一个小东西.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use JavaScript to realize the automatic prompt function of the input box content of the form? Introduction: The automatic prompt function of the form input box content is very common in web applications. It can help users quickly enter the correct content. This article will introduce how to use JavaScript to achieve this function and provide specific code examples. Create the HTML structure First, we need to create an HTML structure that contains the input box and the auto-suggestion list. You can use the following code: <!DOCTYP

The clustering effect evaluation problem in the clustering algorithm requires specific code examples. Clustering is an unsupervised learning method that groups similar samples into one category by clustering data. In clustering algorithms, how to evaluate the effect of clustering is an important issue. This article will introduce several commonly used clustering effect evaluation indicators and give corresponding code examples. 1. Clustering effect evaluation index Silhouette Coefficient Silhouette coefficient evaluates the clustering effect by calculating the closeness of the sample and the degree of separation from other clusters.

How to use JavaScript to implement real-time verification of the input box content of a form? In many web applications, forms are the most common way of interaction between users and the system. However, the content entered by the user often needs to be validated to ensure the accuracy and completeness of the data. In this article, we will learn how to use JavaScript to implement real-time verification of the content of the form's input box and provide specific code examples. Creating the form First we need to create a simple table in HTML

How to use HTML, CSS and jQuery to implement the advanced function of automatic saving of forms. Forms are one of the most common elements in modern web applications. When users enter form data, how to implement the automatic saving function can not only improve the user experience, but also ensure data security. This article will introduce how to use HTML, CSS and jQuery to implement the automatic saving function of the form, and attach specific code examples. 1. Structure of HTML form. Let’s first create a simple HTML form.

Known for its powerful performance and versatile features, the iPhone is not immune to the occasional hiccup or technical difficulty, a common trait among complex electronic devices. Experiencing iPhone problems can be frustrating, but usually no alarm is needed. In this comprehensive guide, we aim to demystify some of the most commonly encountered challenges associated with iPhone usage. Our step-by-step approach is designed to help you resolve these common issues, providing practical solutions and troubleshooting tips to get your equipment back in peak working order. Whether you're facing a glitch or a more complex problem, this article can help you resolve them effectively. General Troubleshooting Tips Before delving into specific troubleshooting steps, here are some helpful

To solve the problem that jQuery.val() cannot be used, specific code examples are required. For front-end developers, using jQuery is one of the common operations. Among them, using the .val() method to get or set the value of a form element is a very common operation. However, in some specific cases, the problem of not being able to use the .val() method may arise. This article will introduce some common situations and solutions, and provide specific code examples. Problem Description When using jQuery to develop front-end pages, sometimes you will encounter

The label acquisition problem in weakly supervised learning requires specific code examples. Introduction: Weakly supervised learning is a machine learning method that uses weak labels for training. Different from traditional supervised learning, weakly supervised learning only needs to use fewer labels to train the model, rather than each sample needs to have an accurate label. However, in weakly supervised learning, how to accurately obtain useful information from weak labels is a key issue. This article will introduce the label acquisition problem in weakly supervised learning and give specific code examples. Introduction to the label acquisition problem in weakly supervised learning:

Forms are an integral part of writing a website or application. Laravel, as a popular PHP framework, provides rich and powerful form classes, making form processing easier and more efficient. This article will introduce some tips on using Laravel form classes to help you improve development efficiency. The following explains in detail through specific code examples. Creating a form To create a form in Laravel, you first need to write the corresponding HTML form in the view. When working with forms, you can use Laravel
