$admin _pw= "admin";//admin password $uploaddir = "upload";//Upload Directory Session_Start (); if ($_get[' action ']== "GetCode") { Setcode (); Exit (); } if ($_post[' password ']== $admin _pw && $_post[' yz ']==$_session[' Yzcode ']) { $_session[' logined ']= $admin _pw; } if ($_get[' action ']== "logout") { $_session[' logined ']= ""; Header ("Location:". $_server[' php_self '); Exit (); } if ($_session[' logined ']!= $admin _PW) { ?>
<title>Please login</title>
} Else { ?>
<title>File Upload</title>
if ($_post[' ac ']== "upload") { $fileall =explode ('. ', $_files[' file ' [' name ']); $filetype = $fileall [Count ($fileall)-1]; $filename = $uploaddir. " /". $_files[' file ' [' Name ']." _ ". Rand (1,999999999).". $filetype; $fileexists =file_exists ($filename); while ($fileexists ==true) { $filename = $uploaddir. " /". $_files[' file ' [' Name ']." _ ". Rand (1,999999999).". $filetype; $fileexists =file_exists ($filename); } if (Move_uploaded_file ($_files["file"] ["Tmp_name"], $filename)) { $url = "http://". $_server[' server_name '].$_server[' Request_uri ']; echo "File:". $filename. "Upload Successful! File Address:Test "; } Else { echo "File". $filename. " Upload failed! "; } } ?>
Sign Out
} function Setcode () { Header ("Content-type:image/gif"); $border = 0; Whether to border 1 to: 0 do not $how = 4; Verify number of code bits $w = $how *15; Picture width $h = 20; Picture height $fontsize = 5; Font size $alpha = "ABCDEFGHIJKMNOPQRSTUVWXYZ"; Verification Code Content 1: Letters $number = "0123456789"; Verification Code Content 2: Digital $randcode = ""; Validation code string initialization Srand (Double) microtime () *1000000); Initialize random number Seed $im = Imagecreate ($w, $h); Create a validation picture $bgcolor = Imagecolorallocate ($im, 255, 255, 255); Set Background color Imagefill ($im, 0, 0, $bgcolor); Fill background color if ($border) { $black = imagecolorallocate ($im, 0, 0, 0); Set Border color Imagerectangle ($im, 0, 0, $w-1, $h-1, $black);//Draw Border } for ($i =0; $i < $how; $i + +) { $alpha _or_number = Mt_rand (0, 1); Letters or numbers? $str = $alpha _or_number? $alpha: $number; $which = Mt_rand (0, strlen ($str)-1); which character to take $code = substr ($str, $which, 1); Take character $j =! $i? 4: $j +15; Draw character position $color 3 = imagecolorallocate ($im, Mt_rand (0,100), Mt_rand (0,100), Mt_rand (0,100)); Character Color Imagechar ($im, $fontsize, $j, 3, $code, $color 3); Paint characters $randcode. = $code; Add a CAPTCHA string to a bit } $_session[' yzcode '] = $randcode; Imagegif ($im); Imagedestroy ($im); } ?>
|