A simple example of uploading images using PHP similar to AJAx_PHP tutorial

WBOY
Release: 2016-07-13 10:43:21
Original
1389 people have browsed it

We often go on some websites, such as when writing an online resume, and we will find that if we select our picture, it will be immediately displayed on the current page. We often think that this kind of thing can only be realized by ajax. Today I studied a little and found that this kind of thing is not realized by ajax.

In the end, we used our basic knowledge of FORM in HTML to implement uploading. Okay, now I will write down what I know for study purposes. Of course, these are just my own study notes. If there are any mistakes, I hope colleagues can give me some pointers.

First of all, let’s make it clear that when uploading images, we still use .

But how can I display the uploaded images without refreshing? Here we need to have an understanding of .

Friends who have used this tag know that it can divide your page into several parts, and each part can have its own URL, that is, several different pages can be displayed. At this point, maybe some friends already know what this is about. Yes, this principle is used to upload pictures. It looks like they are on the same page without jumping, but in fact it has already jumped, but we didn't see it. Okay, here is a simple example, I hope it will be helpful to everyone. (php+html)

The first is the index.php page, the code is as simple as follows:

The code is as follows
 代码如下 复制代码






Copy code

 代码如下 复制代码

//echo $_FILES["tValue"]["tmp_name"];
if(move_uploaded_file($_FILES["tValue"]["tmp_name"], “img/a.jpg”))
{
echo “”;
}
?>






Then there is the hello.php page, which is the page where images are uploaded

The code is as follows

Copy code

//echo $_FILES["tValue"]["tmp_name"];
if(move_uploaded_file($_FILES["tValue"]["tmp_name"], “img/a.jpg”))
{
echo “”;
}
?>

It can be said that it is completed. These few lines of code can achieve the effect we need.

Here’s an analysis: First there is a target in the form, and its value is an iframe inside it. This means that after we submit, the page will be displayed in this iframe, From the definition of iframe, its content is hello.php. So after our form is submitted, it goes directly to this iframe, so the page will not jump, but we have completed the above Upload, from the perspective of hello.php, it will choose to display the image after uploading. From the above, we can know that the content of hello.php will be displayed in the iframe, so the final effect we see is that the page does not jump. , we can make an effect similar to ajax implementation, and after uploading the image, it can be displayed currently.
http://www.bkjia.com/PHPjc/633166.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633166.htmlTechArticleWe often go to some websites, such as when writing an online resume, and we will find that we have to select our pictures. It will be displayed immediately on the current page. We often think that this kind of thing is only...
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