Php file Upload management system _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags php file upload
Log on to the file upload management system using php. This article will introduce you to a good php file Upload management system that requires logon. For more information about simple functions, see. The code is as follows: Copy the code? Php $ admin _ this article will introduce you to a good php file Upload management system that requires logon. you can refer to the php file Upload management system with simple functions and knowledge.
The code is as follows:

$ Admin_pw = "admin"; // manage the 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 on





}
Else
{
?>




File Upload


If ($ _ POST ['AC'] = "upload ")
{
$ Fileall = explode ('.', $ _ FILES ['file'] ['name']);
$ Filetype = $ fileall [count ($ fileall)-1];
$ Filename = $ uploaddir. "/". $ _ FILES ['file'] ['name']. "_". rand (1,99999999999). ".". $ filetype;
$ Fileexists = file_exists ($ filename );
While ($ fileexists = true)
{
$ Filename = $ uploaddir. "/". $ _ FILES ['file'] ['name']. "_". rand (1,99999999999). ".". $ 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! ";
}
}
?>

Log out




}


Function setcode ()
{
Header ("Content-type: image/gif ");
$ Border = 0; // whether the border is required; 1: 0: not required
$ How = 4; // Number of digits of the verification code
$ W = $ how * 15; // image width
$ H = 20; // Image height
$ Fontsize = 5; // font size
$ Alpha = "abcdefghijkmnopqrstuvwxyz"; // verification code content 1: letter
$ Number = "0123456789"; // verification code content 2: number
$ Randcode = ""; // verification code string initialization
Srand (double) microtime () * 1000000); // initialize the random number seed
$ Im = ImageCreate ($ w, $ h); // Create a verification image
$ Bgcolor = ImageColorAllocate ($ im, 255,255,255); // you can specify the background color.
ImageFill ($ im, 0, 0, $ bgcolor); // fill the background color
If ($ border)
{
$ Black = ImageColorAllocate ($ im, 0, 0, 0); // you can specify the border color.
ImageRectangle ($ im, 0, 0, $ W-1, $ H-1, $ black); // draw a 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); // specify the character
$ Code = substr ($ str, $ which, 1); // Obtain the character
$ J =! $ I? 4: $ j + 15; // specifies the position of the painted character.
$ Color3 = ImageColorAllocate ($ im, mt_rand (0,100), mt_rand (0,100), mt_rand (0,100); // character color
ImageChar ($ im, $ fontsize, $ j, 3, $ code, $ color3); // draw characters
$ Randcode. = $ code; // add a verification code string to a bit by bit
}
$ _ SESSION ['yzcode'] = $ randcode;
Imagegif ($ im );
ImageDestroy ($ im );
}
?>


The upload file management system has simple functions. For more information, see. The code is as follows? Php $ admin _...

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.