PHP No refresh using IFRAME implementation page no refresh upload file (_php) tutorial

Source: Internet
Author: User
Tags custom name
Use the target property and IFrame of the form form

One, upload the file of a PHP tutorial method.
The method takes a $file parameter, which is the $_files variable obtained from the client, returns the renamed file name, and returns an empty string if the upload fails.
PHP code

function UploadFile ($file) {
Upload path $destinationpath = "./upload/";
if (!file_exists ($destinationpath)) {
mkdir ($destinationpath, 0777); }
Renaming
$filename = Date (' Ymdhis '). '_' . Iconv (' Utf-8 ', ' gb2312 ', basename ($file [' name ']);
if (Move_uploaded_file ($file [' Tmp_name '], $destinationpath. $filename)) {return iconv (' gb2312 ', ' utf-8 ', $filename);
} return ';
}

Second, the client HTML code
Here's where the trick is, add another iframe to implement. The form label form defines a property target, which is interpreted as follows:
[Pre]target Property:
_blank----------New Open window
_self-----------itself
_top------------Main Frame
_parent---------Parent Frame
The custom name-----appears in the frame structure and will open the link within the frame of the name

In this case, the IFRAME name is used, so the form will open the link within the IFRAME when it is submitted (that is, no refresh, exactly
Feel no refresh)
When the form commits, call the Startupload method, which is, of course, the JS definition.
[/pre] [Pre] In addition, we define a span to display the prompt information. The code is as follows:
[/pre]xhtml Code

Import file:
<iframe id= "Upload_target" name= "Upload_target" src= "#" style= "width:0;height:0;border:0px solid #fff;" >iframe ><br/> form> <span id= "Info" >span> </blockquote><p>1 2 <br></p><p Align= "left" ><span id= "url" itemprop= "url" >http://www.bkjia.com/phpjc/444809.html</span><span Id= "Indexurl" itemprop= "Indexurl" >www.bkjia.com</span><span id= "isoriginal" itemprop= "isOriginal" > True</span><span id= "Isbasedonurl" itemprop= "Isbasedonurl" >http://www.bkjia.com/phpjc/444809.html </span><span id= "Genre" itemprop= "genre" >techarticle</span><span id= "description" itemprop= " Description "> A php Tutorial method for uploading files using the target property of form form and iframe one. The method accepts a $file parameter, which is the $_files variable obtained from the client, returns the re ... </span></p><li ><i class= "Layui-icon" >&# xe63a; </iframe>
Related Article

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.