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"