It took another half a day to write a php Upload class solution.

Source: Internet
Author: User
I spent another half of my time writing a php Upload class. it wasn't long before I learned PHP. I spent most of my time writing a PHP Upload class for better practice and familiarity with php. I will take a note here, you are welcome to modify and optimize this class. PHPcodeup_class.php & lt ;? PhpclassUpFile {private $ inputFile; the file domain name private $ tm spent another half a day writing a php Upload class
It wasn't long before I learned PHP. I spent most of my time writing a PHP Upload class for better practice and familiarity with php. I would like to take a note here and welcome my friends to modify and optimize this class.

PHP code
  // Up_class.php
  * $ UpFolder (the folder saved to the server );
* $ IsRename (rename the uploaded file with the value y | n );
* $ ReType (value returned after successful Upload: n indicates the returned file name, pn indicates the returned path and file name, and j indicates the returned js [to be extended]).
* $ UpExt (categories of files to be uploaded, because different forms require different Upload file types. for example, form A can only upload images, and form B can only upload Wei compressed files );
* $ MaxSize (limit the size of uploaded files)
* @ Author: 256kb * @ 2012-5-1 */public function _ construct ($ inputFile, $ upExt = 0, $ reType = 'pn ', $ upFolder = 'upload /', $ isRename = 'y', $ maxSize = 10485760) {$ this-> inputFile = $ inputFile; $ this-> reType = $ reType; $ this-> upMaxSize = $ maxSize; $ this-> allowFile = $ upExt; $ this-> upFolder = $ upFolder; $ this-> isReName = $ isRename; // $ this-> errorInt =-1 ;} public function upFile () {$ _ file_arr = $ _ FILES [$ this-> inputFile]; $ this-> errorInt = $ _ file_arr ['error']; if (is_uploaded_file ($ _ file_arr ['tmp _ name']) {if ($ _ file_arr ['tmp _ name']) {$ this-> tmpName =$ _ file_arr ['name']; $ this-> upMaxSize =$ _ file_arr ['size']; $ this-> fileType =$ _ file_arr ['type']; $ this-> tmpPath =$ _ file_arr ['tmp _ name']; $ this-> fileSize = $ _ file_arr ['size']; if ($ this-> upMaxSize> $ this-> upMaxSize) {$ this-> errorInt = 6; // size Exceeds website limit} if (! $ This-> isAllow () {$ this-> errorInt = 8; // The system does not allow this type of files} if ($ this-> isReName = 'y ') {$ this-> savePath = $ this-> upFolder. $ this-> getFolder (). '/'. $ this-> getNewName (); $ this-> endFileName = $ this-> getNewName ();} else {$ this-> savePath = $ this-> upFolder. $ this-> getFolder (). '/'. $ this-> tmpName; $ this-> endFileName = $ this-> tmpName;} // echo $ this-> errorInt; if (! $ This-> errorInt >=1) {move_uploaded_file ($ this-> tmpPath, $ this-> savePath) ;}}} public function getFileUrl () {switch ($ this-> reType) {case 'n': return $ this-> endFileName; break; case 'pn ': return $ this-> savePath; break; case 'js': return"

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.