$_files: Variable submitted to script via HTTP POST file upload, similar to old array $http_post_files array (still valid but opposed to use) details can be found in POST method upload
The contents of the $_files array are as follows:
$_files[' myFile ' [' Name '] The original name of the client file
The MIME type of the $_files[' myFile ' [' type '] file requires the browser to provide support for that information, such as "Image/gif"
$_files[' myFile ' [' size '] the size of the uploaded file, in bytes
$_files[' myFile ' [' tmp_name '] files are uploaded on the server after the temporary file name stored in the system is generally the default, can be specified in PHP.ini Upload_tmp_dir, but with the putenv () function setting is not working
$_files[' myFile ' [' Error '] and the file upload related error code, [' Error '] is added in PHP 4.2.0, here is its description: (they became constant after PHP3.0)
UPLOAD_ERR_OK value: 0; No error occurred, file upload succeeded
Upload_err_ini_size value: 1; The uploaded file exceeds the value of the Upload_max_filesize option limit in php.ini
Upload_err_form_size value: 2; the size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form
Upload_err_partial value: 3; Files are only partially uploaded
Upload_err_no_file value: 4; No file is uploaded, value: 5; Upload file size of 0
Note:
1. after the file is uploaded, it is stored in the temp directory by default, and it must be removed from the temp directory or moved elsewhere, if not, it will be deleted. That is, regardless of whether or not the upload succeeds, the files in the temp directory will be deleted after the script executes. So before you delete it, copy it to another location using PHP's copy () function, and it's time to upload the file.
2. before PHP 4.1.0 The name of the array is $HTTP _post_files, and it is not an automatic global variable like $_files. PHP 3 does not support $HTTP _post_files arrays.
3. when uploading a file with a form, be sure to add the attribute content enctype= "Multipart/form-data", otherwise you will be reported an exception when obtaining the file information with $_files[filename].
HTML section
1 <formname= "Uploadfrom"ID= "Uploadfrom"Action= "gteditupfile.php"Method= "POST"Target= "Tarframe"enctype= "Multipart/form-data">2Upload file:<inputclass= "Upload_file"type= "File"name= "Upfile">3 </form>4 <iframesrc=""width= "0"Height= "0"style= "Display:none;"name= "Tarframe"></iframe>5 <spanID= "LResult"></span>
JS section
1 $ (function() {2 $ (". Upload_file"). Change (function() { 3 $ ("#uploadFrom"). Submit (); 4 }); 5 }); 6 function stopsend (str) {7 $ ("#lResult"). Text (""); 8 $ ("#lResult"). Text (str); 9 }
Received data page for form submission gteditupfile.php
1<?php//* Connection Database2 $file=$_files[' Upfile '];3 $dir= "gtfile/"; //File upload directory 4 $filename=$file[' Name '];//save file name for database5 $file[' name '] =Iconv(' UTF-8 ', ' GBK ',$file[' Name ']); //conversion format, in order to avoid the occurrence of Chinese garbled situation 6 //Upload Directory If there is a file with the same name, avoid overwriting7 if(file_exists($dir.$file[' Name '])){8 Echo"<script>parent.stopsend (' upload failed!") (the file name already exists!) ) </script> ";//invoking the JS function of the IFRAME parent window9 Exit();Ten } One //You can also $file[' size ']/$file [' type '] for file type, size, respectively. A $sql= "Select*from tb_table";//Check to see if the file information exists in the database, and if so, remove the junk data from the database before you accumulate - $query=mysql_query($sql); - if(mysql_num_rows($query) >0){ the Echo"<script>parent.stopsend (' upload failed!) Please delete the original file first! ') </script> ";//invoking the JS function of the IFRAME parent window - Exit(); - } - //Uploading Files + if(Move_uploaded_file($file[' Tmp_name '],$dir.$file[' Name '])){ - $sql= "SQL statement";//data processing such as database saving modification + if(mysql_query($sql)){ A Echo"<script>parent.stopsend (' upload success! ') </script> "; at}Else{ - Echo"<script>parent.stopsend (' upload success! But the data processing failed! ') </script> "; - } -}Else{ - Echo"<script>parent.stopsend (' upload failed! ') </script> "; - } in?>
$_file parameter detailed and simple <form> no refresh upload file