PHP file upload management system for login operation_PHP tutorial

WBOY
Release: 2016-07-20 11:12:16
Original
1433 people have browsed it

This article will introduce to you a good PHP file upload management system that requires login. The function is simple and students who need to know more can refer to it.

The code is as follows Copy code

$admin_pw="admin";// Management 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)
{
?>




Please log in

< ;body>


Enter password:
Verification characters: Verification code




}
else
{
?>




File upload

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." Uploaded successfully!
File address:Test";
}
else
{
echo "File".$filename ."Upload failed! ";
}
}
?>

Select file:< input type="file" name="file" id="file" width="100px" />

Log out

}


function setcode()
{
Header("Content-type: image/gif");
$border = 0; //Whether you want border 1 Yes: 0 No
$how = 4; //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: Numbers
$randcode = ""; //Verification code String initialization
srand((double)microtime()*1000000); //Initialize random number seed
$im = ImageCreate($w, $h); //Create verification image
$bgcolor = ImageColorAllocate($im, 255, 255, 255); //Set the background color
ImageFill($im, 0, 0, $bgcolor); //Fill the background color
if($border)
{
$black = ImageColorAllocate($im, 0, 0, 0); //Set the 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); //Get character
$j = !$i ? 4 : $j+15; //Draw character position
$color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100) , mt_rand(0,100)); //Character random color
ImageChar($im, $fontsize, $j, 3, $code, $color3); //Draw character
$randcode .= $code; / /Add the verification code string bit by bit
}
$_SESSION['yzcode'] = $randcode;
Imagegif($im);
ImageDestroy($im);
}
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444593.htmlTechArticleThis article will introduce to you a good PHP file upload management system that requires login. It has simple functions and needs to be understood. Students can refer to it. The code is as follows Copy the code ?php $admin_...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template