Simple PHP file Upload class for beginners-PHP source code

Source: Internet
Author: User
Tags php file upload
This article mainly shares a simple php file Upload class for beginners, which has some reference value, interested friends can refer to this article to share a simple php file Upload class for beginners, which has some reference value. interested friends can refer to it.

This article describes PHP multi-file Upload classes and shares them with you for your reference. The details are as follows:

 _ Destination = $ path; $ this-> _ uploaded = $ _ FILES;}/*** move FILE **/public function move () {$ filed = current ($ this-> _ uploaded); $ isOk = $ this-> checkError ($ filed ['name'], $ filed ['error']); // debug OK if ($ isOk) {$ sizeOk = $ this-> checkSize ($ filed ['name'], $ filed ['size']); $ typeOk = $ this-> checkType ($ filed ['name'], $ filed ['type']); if ($ sizeOk & $ typeOk) {$ success = move_uploaded_file ($ filed ['tmp _ nam E '], $ this-> _ destination. $ filed ['name']); if ($ success) {$ this-> _ messages [] = $ filed ['name']. "File uploaded successfully";} else {$ this-> _ messages [] = $ filed ['name']. "File upload failed" ;}}}/ *** query the content of the messages array **/public function getMessages () {return $ this-> _ messages ;} /*** check the size of the uploaded file * @ param mix $ string * @ param int $ size */public function checkSize ($ filename, $ size) {if ($ size = 0) {return false;} else if ($ size> $ This-> _ max) {$ this-> _ messages [] = "the file size exceeds the upload limit ". $ this-> getMaxsize (); return false;} else {return true ;}} /*** check the type of the uploaded file * @ param mix $ filename * @ param mix $ type */protected function checkType ($ filename, $ type) {if (! In_array ($ type, $ this-> _ permited) {$ this-> _ messages [] = "this file type is not an allowed Upload type"; return false ;} else {return true ;}/ *** get file size **/public function getMaxsize () {return number_format ($ this-> _ max/1024, 1 ). 'KB';}/*** check Upload error * @ param mix $ filename * @ param int $ error **/public function checkError ($ filename, $ error) {switch ($ error) {case 0: return true; case 1: case 2: $ this-> _ messages [] = "The file is too large! "; Return true; case 3: $ this-> _ messages [] =" file upload error! "; Return false; case 4: $ this-> _ messages [] =" no file is selected! "; Return false; default: $ this-> _ messages [] =" system error! "; Return false ;}}?>

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.