The whole system only with code all with PHP, no JS, no regular ... Pure PHP ... In fact, other I will not hehe ...
Here is the HTML code for the original form ...
Uploading file Forms
Copy CodeThe code is as follows:
The meaning of enctype= "Multipart/form-data" in the form is to set the MIME encoding of the form. By default, this encoding format is application/x-www-form-urlencoded, cannot be used for file upload, only the use of multipart/form-data, to complete the transfer of file data, the following operation. Enctype= " Multipart/form-data "is to upload binary data; The values in the form are passed through in 2-stream mode.
This sentence seems to be useless ... I thought this could limit the upload file size, upload file size only in php.ini or later upload files in the script set ... My program is directly set up in the PHP.ini upload_max_filesize=6m.
Here is the upload program
Code
Copy CodeThe code is as follows:
$uploaddir = "./map/";
$typearr =array ("rar", "Zip", "w3m", "w3x");
$findstr =array ("/", "\ \", "", "<", ">"); Filtering the name
$mapname =str_replace ($findstr, ', ($_post[' mapname '));
Take extension
function Upfiletype ($filename) {
$arr =explode ('. ', $filename);
$a =count ($arr)-1;
return $arr [$a];
}
String is not a purely numeric
function IsNo ($STR) {
$intarr =array (' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' 0 ', '. ');
$a =str_replace ($intarr, ", $STR);
return ($a = = "")? 1:0;
}
control Window Size///////
function html () {
Echo <<
<title>File Upload</title>
Eof
}
if (IsNo ($mapname)) {
HTML ();
Exit (' Enter the correct map name ');
}
Determine if there is a file upload
if (!is_uploaded_file ($_files[' map ' [' tmp_name '])) {
HTML ();
Exit ("You have not uploaded files or uploaded files greater than 6M");
}
Judging if it's a duplicate upload
$clintfilename =str_replace ($findstr, ', $_files[' map ' [' name ']);
if (isset ($_cookie[' upload ')) {
foreach ($_cookie[' upload ') as $value) {
if ($value = = $clintfilename) {
HTML ();
Exit ("Please do not upload again");
}
}
}
$filetype =strtolower (Upfiletype ($_files[' map ' [' name ']));
if (!in_array ($filetype, $typearr)) {
HTML ();
Exit ("Please upload the correct map file, support rar,zip,w3m,w3x");
}
Determine if the server file exists
$filename = $mapname. '. '. $filetype;
for ($a =1; $fopen = @fopen (($uploaddir. $filename), "R"), $a + +) {
$filename = $mapname. " $a ". '. $filetype;
Fclose ($fopen);
}
Transfer file start;
$filepath = $uploaddir. $filename;
if (Move_uploaded_file ($_files[' map '] [' tmp_name '], $filepath)) {
Set a cookie to see if there is a duplicate upload
Setcookie ("upload[]", $clintfilename, Time () +60*12);
HTML ();
echo "Upload success";
$log =fopen ("Upload.log", "A7");
$logtxt =date ("YMD"). "|". Date ("H:i"). "|". $_server["REMOTE_ADDR"]. "|". $filename. " \ r \ n ";
Fwrite ($log, $logtxt);
}
?>
Because it is the first time to write ... A lot of places have problems, and in the time of writing is changed and changed .... Forget more advice
http://www.bkjia.com/PHPjc/320744.html www.bkjia.com true http://www.bkjia.com/PHPjc/320744.html techarticle the whole system only with code all with PHP, no JS, no regular ... Pure PHP ... In fact, other I will not hehe ... Here is the HTML code for the original form ... Upload file Form copy Code code ...