Home >Backend Development >PHP Tutorial >PHP uses iframe to upload files without refreshing the page (1/2)_PHP tutorial
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
[pre]target attribute:function uploadfile($file) {
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:
$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
_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)
[/pre][pre]In addition, we also define a span to display prompt information. The code is as follows:
[/pre]xhtml code