In the end, we use the FORM in HTML to implement the upload. All right, now I will write what I know and use it for learning. Of course, this is just my own study notes. If there is something wrong, I hope you can give me some advice.
First, let's make it clear that we still use <from… to upload images .... Enctype = "multipart/form-data">.
But how can I display the uploaded image without refreshing it? Here we need to understand <iframe> </iframe>.
Anyone who has used this tag knows that it can divide your page into several parts, and each part can have its own url, that is, display several different pages. Speaking of this, some friends may already know what this is about. That's right. This principle is used to upload images. It looks like on the same page, there is no jump, and in fact it has already jumped, but we didn't see it. Okay. Here is a simple example. I hope it will help you all. (Php + html)
The first is the index. php page. The code is as follows:
| The code is as follows: |
Copy code |
|
<Form id = "content" action = "hello. php" method = "post" target = "yframe" enctype = "multipart/form-data">
<Input type = "file" name = "tValue">
<Input type = "submit" value = "submit">
<Iframe name = "yframe" src = "hello. php" style = "border: none;"> </iframe>
</Form>
<Input type = "text"> |
Then there is the hello. php page, that is, the page for uploading images.
| The code is as follows: |
Copy code |
|
<? Php
// Echo $ _ FILES ["tValue"] ["tmp_name"];
If (move_uploaded_file ($ _ FILES ["tValue"] ["tmp_name"], "img/a.jpg "))
{
Echo " ";
}
?> |
This can be said to have been done, and these lines of code can implement the results we need.
The following is an analysis:
First, there is a target in form, and its value is an iframe in it. This means that after we submit the target, the page will be displayed in this iframe,
According to the iframe definition, its content is hello. php. Therefore, after the form is submitted, it is directly included in the iframe, so the page will not jump, but we have finished
In. php: After the image is uploaded, it will display the image. php content is displayed in iframe, so the final result we see is that the page is not redirected, and we can make an effect similar to ajax implementation, the uploaded image can be displayed at the moment.