Php+iframe implementation of the page without the need to refresh the asynchronous file upload, _php tutorial

Source: Internet
Author: User

Php+iframe implementation of the page does not need to refresh the asynchronous file upload,


This article describes the Php+iframe implementation of the page does not need to refresh the asynchronous file upload, is very useful common skills. Share to everyone for your reference. The specific analysis is as follows:

When it comes to IFRAME, fewer people are using it now, and many people believe it should be replaced by Ajax, and that's true, because Ajax is great.

However, there is a situation of implementation I still choose the IFRAME, this is the paper to say the asynchronous upload of files, interested can try, if the original Ajax to achieve should be more complex.

First of all to give the beginner to fill the basic knowledge:

1. The iframe label will typically specify its name attribute for identification;
2. The destination of the submission is determined by the action (target address) and target (the target window, default _self) in the form form;
3. Point the target in the form to the name of the IFrame, and the form can be submitted to the hidden frame iframe;
4. The content in the IFRAME is actually a page, in which the parent object in JS refers to the Father page, which is the page embedded in the IFRAME;
5. PHP uses the Move_uploaded_file () function to implement file uploads, and $_files array stores information about uploaded files.

This article realizes is a user chooses the avatar file to upload immediately and displays on the page The example, the nonsense does not say much, the idea is like this:

1. Embed an IFRAME in the form and set the name attribute value;
2. When the value of the selected file upload control changes, a JS function is triggered, which submits the form to the IFRAME, and the page embedded in the IFRAME is used to process the file upload;
3. After uploading the file in the IFRAME, the parent page is manipulated in JS, the image is displayed in a specific tag, and the saved address of the image is assigned to a hidden field;
4. Back to the original page, now both completed the file upload, but also in the hidden domain record the path of the file, the whole process did not refresh the page;
5. The last user simply submits the original page when the value of the action and target property of the form is reset.

Here is the code for the effect and implementation:

The upload.php page is as follows:

   
 
  IFrame Asynchronous File Upload   

IFrame Asynchronous File Upload

<?php //page submission after display of relevant information if (Isset ($_post[' submitted ')) { $html = '

Upload success!

'; $html. = '

User name: '. Htmlspecialchars ($_post[' username '). '

'; $html. = '

Avatar address: '. Htmlspecialchars ($_post[' photo '). '

'; $html. = ' '; Echo $html; }?>

The proceedupload.php page is as follows:

<?php//Here is only a specific image format for example, should be dynamically acquired $url = ' upload/img '. Time (). '. jpg '; if (Move_uploaded_file ($_files[' Uploadphoto ' [' tmp_name '], $url)) {   //delete previous picture   $_post[' photo ']!== ' & & Unlink ($_post[' photo ');?>      
 
  
  
   
 
   <?php}?>

Interested friends can test run the example of this article, I believe this article on the PHP program design of the study has some reference value.




http://www.bkjia.com/PHPjc/879725.html www.bkjia.com true http://www.bkjia.com/PHPjc/879725.html techarticle php+iframe Implementation of the page does not need to refresh the asynchronous file upload, this article describes the Php+iframe implementation of the page does not need to refresh the asynchronous file upload, is very useful common skills. Share to the big ...

  • 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.