This article introduces you a good php file upload management system that needs to be logged in. Students who need to know can refer to it if they have simple functions.
The code is as follows
<?php $admin_pw="admin";//Manage password$uploaddir="upload";//Upload directorysession_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) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Please log in</title> </head> <body> <form action="" method="post"> Enter your password:<input type="password" name="password" style="width:100px;" /><br />Verify characters:<input type="text" style="width:40px;" name="yz" /><a href="#" onclick="='?action=getcode';"><img src="?action=getcode" alt="verification code" name="tzm" /></a><br /><input type="submit" value="enter management" /></form> </body> </html> <?php } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>File upload</title> </head> <body> <?php 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 "document:".$filename." Upload successfully!<br>File address:<input type=text style='width:350px;' value=".dirname($url)."/".$filename." /><a href=".dirname($url)."/".$filename." target="_blank">test</a>"; } else { echo "document".$filename."Upload failed!"; } } ?> <form action="" method="post" enctype="multipart/form-data"> Select a file:<input type="file" name="file" width="100px" /><input type="hidden" name="ac" value="upload" /><input type="submit" value="Upload" /> </form> <p><a href="?action=logout">Log out</a></p> </body> </html> <?php } function setcode() { Header("Content-type: image/gif"); $border = 0; //Do you want borders? 1 Want: 0 Don't $how = 4; //The number of verification code digits $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: Number $randcode = ""; //Initialization of verification code string srand((double)microtime()*1000000); //Initialize random number seed $im = ImageCreate($w, $h); //Create verification image $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); //Letter or number $str = $alpha_or_number ? $alpha : $number; $which = mt_rand(0, strlen($str)-1); //Which character to take $code = substr($str, $which, 1); //Get characters $j = !$i ? 4 : $j+15; //Draw character position $color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); //The character will be colored ImageChar($im, $fontsize, $j, 3, $code, $color3); //Draw characters $randcode .= $code; //Add verification code string bit by bit } $_SESSION['yzcode'] = $randcode; Imagegif($im); ImageDestroy($im); } ?>
For more study materials, please pay attention to the special topic "Management system development》。
The above is to learn the php file upload management system that you need to log in with you. You can beautify the login according to your hobbies. I hope you can like this article.