Iframe: Implementation of brushless new file upload-PHP Tutorial

Source: Internet
Author: User
Iframe: The Implementation Program for refreshing file uploads. Iframe: in fact, the upload program page is opened on the current page, a bit like a partial ajax refresh, but we put it to the iframe page for upload, at the same time, our iframe refreshing file upload is actually opening the upload program page on the current page, a bit like a partial ajax refresh, but we put it in the iframe page for upload, at the same time, the iframe page is hidden.

A simple iframe Upload example:

In this example, the iframe name is used, so the link is opened in the iframe when the form is submitted
Feel refreshed)
Call the startUpload method when submitting a form. of course, this is defined by JS.


The front page index.html is mainly a form and a js callback function. When uploading a file, the method and enctype attributes of the form must be the same as the following code. Set the target value to the name of iframe, so that you can upload files without any need.

The code is as follows:

Upload files

Script
Function CallbackFunction (str ){
Alert ("uploaded successfully ");
}
Script


Uploadfile. php on the background Upload processing page. this code is a simple Upload code without error and exception handling. After the upload code is executed, you need to tell the parent page that the upload has been completed. Therefore, you can call the callback function CallbackFunction of the parent page on this page. This function can be defined as a parameter.

The code is as follows:

Set_time_limit (0 );
If ($ _ SERVER ['request _ method'] = 'post '){
Move_uploaded_file ($ _ FILES ["test_file"] ["tmp_name"],
Dirname ($ _ SERVER ['script _ filename']). "/UploadTemp/". $ _ FILES ["test_file"] ["name"]);
Echo "script window. parent. CallbackFunction (); script";
}
?>

The above is a simple method to use iframe to implement the upload of files without any need. if you want a robust program, you need to refine it.


Example 2

PHP uses iframe to upload files and return values to the parent framework

In fact, fresh water uses this method. I can see that my shoes blog is written in this way. You can easily paste it.

The code is as follows:

If ($ result)
{
Echo "Upload successful! File path: ". $ file2;
Echo'';
Echo'{script}parent.doc ument. form1.img. value = document. getElementById ("img"). value; script ';
}

After the file is uploaded successfully, write the file path to a hidden domain (img), and then use the DOM principle to send the VALUE in the hidden domain to the img text box in the form form1 of the parent framework:
OK. Let's take a look at the fresh water.
The freshwater editor uses tinyMCE, so there is a little difference.
My form page:

The code is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.