Home >Backend Development >PHP Tutorial >PHP uses iframe to upload files without refreshing the page (1/2)_PHP tutorial

PHP uses iframe to upload files without refreshing the page (1/2)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:09:131294browse

Using the target attribute of the form form and iframe

1. A PHP tutorial method for uploading files.
This method accepts a $file parameter, which is the $_files variable obtained from the client, and returns the renamed file name. If the upload fails, an empty string is returned.
php code

function uploadfile($file) {
$destinationpath = "./upload/";
if (!file_exists($destinationpath)) {
               mkdir($destinationpath, 0777);                                                                                                                                                   . ($file['name']));
if (move_uploaded_file($file['tmp_name'], $destinationpath . $filename)) { return iconv('gb2312', 'utf-8', $filename) ; } Return '';
}


II. The client HTML code

This is exactly where the skills are, add another iframe to implement. The form tag form defines an attribute target, which is explained as follows:
[pre]target attribute:

_blank ---------- New window
_self ------ ----- Self
_top ------------ Main frame
_parent --------- Parent frame
custom name ----- Appearing in the frame structure, the link will be opened in the frame of that name

In this example, the iframe name is used, so the link will be opened in the iframe when the form is submitted (that is, there is no refresh, to be precise it should be
No refresh feeling)

When the form is submitted, the startupload method is called, of course this is defined by js.

[/pre][pre]In addition, we also define a span to display prompt information. The code is as follows:
[/pre]xhtml code


Import file: