Php simple file upload code-PHP source code

Source: Internet
Author: User
Ec (2); & lt; html & gt; & lt; head & gt; & lt; title & gt; filemanage & lt; title & gt; & lt; head & gt; & lt; body & gt; & lt; center & gt; & lt; p & gt; & lt; h2 & gt; File Management & lt; h2 & gt; & lt; p & gt; & lt; br & gt; & lt; tableborder1 & gt; & lt; tr script ec (2); script



Filemanage



File Management






Include ("conn. php ");// Echo'
File ID File Name File Size Upload time Download Delete








';$ Rs = $ db-> query ("select * from filem order by f_id DESC ");$ I = 1;While ($ row = $ rs-> fetch_assoc ()){$ Size = $ row ['f _ size ']/1024;Echo" ";}Echo'
". $ I ++ ." ". $ Row ['f _ name']." ". Number_format ($ size, 2, '.',''). "KB ". $ Row ['f _ date']." Download Delete
';
Unset ($ rs );
$ Db-> close ();
?>





Uploadfile



If (! $ _ FILES ["userfile"] ["name"]) exit;
// Echo $ _ FILES ['userfile'] ['type'];
If ($ _ FILES ['userfile'] ['error']> 0)
{
Echo 'problem :';
Switch ($ _ FILES ['userfile'] ['error'])
{
Case 1: echo 'file exceeded upload_max_filesize '; break;
Case 2: echo 'cannot exceed 800m'; break;
Case 3: echo 'file only partially uploaded'; break;
Case 4: echo 'no file uploaded'; break;
}
Exit;
}
Else
{// Check whether the uploaded file is of the allowed upload type
$ Tp = array ("gif", "jpeg", "png", "txt", "doc", "rar", "zip", "xls ", "bmp", "wmv", "mp3", "flv", "rmvb", "avi ");
If (! In_array (strtolower (substr (strrchr ($ _ FILES ['userfile'] ['name'], '.'), 1), $ tp ))

{
Echo 'file type error. Please select a file again!
Only files of the rar, zip, jpg, gif, txt, png, bmp, and xls types are allowed ';
Exit;
}

$ Path = "./file/"; // upload path

If (file_exists ($ path. $ _ FILES ['userfile'] ['name']) // you can check whether a file exists.
{
Echo 'file already exists. Please change it and upload it again! ';
Exit;
}

If ($ _ FILES ["userfile"] ["name"])
{
$ File1 = $ _ FILES ["userfile"] ["name"];
$ File2 = $ path. $ file1;
$ Flag = 1;
}
If ($ flag)
$ Result = move_uploaded_file ($ _ FILES ["userfile"] ["tmp_name"], $ file2 );
// Note that the first parameter passed to move_uploaded_file is the temporary file uploaded to the server.
If ($ result)
{

$ Time = date ("Y-m-d ");
// $ Url = $ patch. $ name;
$ Size = $ _ FILES ["userfile"] ["size"];
Include ("conn. php ");
$ Rs = $ db-> query ("insert into filem (f_name, f_url, f_date, f_size) values ('$ file1',' $ file2', '$ time ', '$ size ')");
// $ Rs = $ db-> query ($ SQL );
Echo"

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.