PHP login operation file Upload management System _php Tutorial

Source: Internet
Author: User
Tags php file upload set background
This article to the students to introduce a good need to login PHP file Upload management system, the function is simple to understand the students can refer to.
The code is as follows Copy Code

$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);
}
?>


http://www.bkjia.com/PHPjc/444593.html www.bkjia.com true http://www.bkjia.com/PHPjc/444593.html techarticle This article to the students to introduce a good need to login PHP file Upload management system, the function is simple to understand the students can refer to. Code to copy code like this? PHP $admin _ ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.