It can be directly used in the Rich Text Editor umeditor of the sae platform to rewrite the internal upload class implementation by yourself. class. php simply sets the application mode APP_MODE to sae mode, and sets the domain name of storage when instantiating the Uploader class. None? Php *** CreatedbyJetBrainsPhpStorm. * User: taoqili
It can be directly used in the Rich Text Editor umeditor of the sae platform to rewrite the internal upload class implementation by yourself. class. php simply sets the application mode APP_MODE to sae mode, and sets the domain name of storage when instantiating the Uploader class. None? Php/*** Created by JetBrains PhpStorm. * User: taoqili
It can be directly used in the Rich Text Editor umeditor of the sae platform to rewrite the internal upload class implementation by yourself. class. php simply sets the application mode APP_MODE to sae mode, and sets the domain name of storage when instantiating the Uploader class. <无>
"The file SIZE exceeds the post_max_size limit", "SIZE" => "the file SIZE exceeds the website limit", "TYPE" => "file TYPE not allowed ", "DIR" => "Directory creation failed", "IO" => "input/output error", "UNKNOWN" => "UNKNOWN error ", "MOVE" => "An error occurred while saving the file", "DIR_ERROR" => "failed to create directory "); /*** constructor ** @ param string $ fileField form name * @ param array $ config configuration item * @ param string $ appMode Application Mode * @ param string $ domian sae storage domain name *@ param bool $ base64 whether to parse base64 encoding, can be omitted. If enabled, $ fileField indicates the base64 encoded string form name */public function _ construct ($ fileField, $ config, $ appMode = 'common ', $ domian = 'uploads', $ base64 = false) {$ this-> fileField = $ fileField; $ this-> config = $ config; $ this-> appMode = $ appMode; $ this-> stateInfo = $ this-> stateMap [0]; $ this-> upFile ($ base64 );} /*** main processing method for uploading files * @ param $ base64 * @ return mixed */private function upFile ($ base64) {// process bas E64 upload if ("base64" ==$ base64) {$ content =$ _ POST [$ this-> fileField]; $ this-> base64ToImage ($ content); return ;} // process normal uploads $ file = $ this-> file = $ _ FILES [$ this-> fileField]; if (! $ File) {$ this-> stateInfo = $ this-> getStateInfo ('post'); return;} if ($ this-> file ['error']) {$ this-> stateInfo = $ this-> getStateInfo ($ file ['error']); return;} if (! Is_uploaded_file ($ file ['tmp _ name']) {$ this-> stateInfo = $ this-> getStateInfo ("UNKNOWN"); return ;} $ this-> oriName = $ file ['name']; $ this-> fileSize = $ file ['SIZE']; $ this-> fileType = $ this-> getFileExt (); if (! $ This-> checkSize () {$ this-> stateInfo = $ this-> getStateInfo ("SIZE"); return;} if (! $ This-> checkType () {$ this-> stateInfo = $ this-> getStateInfo ("TYPE"); return ;} if ($ this-> appMode = 'common') {$ folder = $ this-> getFolder (); if ($ folder = false) {$ this-> stateInfo = $ this-> getStateInfo ("DIR_ERROR"); return;} $ this-> fullName = $ folder. '/'. $ this-> getName ();} if ($ this-> stateInfo ==$ this-> stateMap [0]) {// normal mode if ($ this-> appMode = 'common') {if (! Move_uploaded_file ($ file ["tmp_name"], $ this-> fullName) {$ this-> stateInfo = $ this-> getStateInfo ("MOVE ");}} elseif ($ this-> appMode = 'sae ') {// sae mode $ storage = new SaeStorage (); // year month day $ save_path = date ('ymmd '); $ save_name = $ save_path. '/'. $ this-> getName (); // use the storage service $ result = $ storage-> upload ($ domian, $ save_name, $ file ["tmp_name"]); // obtain the url access path of the stored file under this domain name if ($ result) {$ Pic_url = $ storage-> getUrl ($ domian, $ save_name); $ this-> fullName = $ pic_url ;} else {$ this-> stateInfo = 'Is my writing incomplete .... ';}}}/*** uploads base64 encoded images * @ param $ base64Data * @ return mixed */private function base64ToImage ($ base64Data) {$ img = base64_decode ($ base64Data); $ this-> fileName = time (). rand (1, 10000 ). ". png "; $ this-> fullName = $ this-> getFolder (). '/'. $ this-> fileName; if (! File_put_contents ($ this-> fullName, $ img) {$ this-> stateInfo = $ this-> getStateInfo ("IO"); return ;} $ this-> oriName = ""; $ this-> fileSize = strlen ($ img); $ this-> fileType = ". png ";}/*** get the information of the currently uploaded file * @ return array */public function getFileInfo () {return array ("originalName" => $ this-> oriName, "name" => $ this-> fileName, "url" => $ this-> fullName, "size" => $ this-> fileSize, "type" ==>$ This-> fileType, "state" =>$ this-> stateInfo );} /*** upload error check ** @ param $ errCode * @ return string */private function getStateInfo ($ errCode) {return! $ This-> stateMap [$ errCode]? $ This-> stateMap ["UNKNOWN"]: $ this-> stateMap [$ errCode];}/*** rename the file * @ return string */private function getName () {return $ this-> fileName = time (). rand (1, 10000 ). $ this-> getFileExt ();}/*** file type check * @ return bool */private function checkType () {return in_array ($ this-> getFileExt (), $ this-> config ["allowFiles"]);}/*** file size check * @ return bool */private function checkSize () {re Turn $ this-> fileSize <= ($ this-> config ["maxSize"] * 1024 );} /*** get file extension * @ return string */private function getFileExt () {return strtolower (strrchr ($ this-> file ["name"], '. ');}/*** automatically creates a storage folder by date * @ return string */private function getFolder () {$ pathStr = $ this-> config ["savePath"]; if (strrchr ($ pathStr ,"/")! = "/") {$ PathStr. = "/";} $ pathStr. = date ("Ymd"); if (! File_exists ($ pathStr) {if (! Mkdir ($ pathStr, 0777, true) {return false ;}return $ pathStr ;}}
"Upload/", // storage folder "maxSize" => 1024*2, // maximum file size allowed, in KB "allowFiles" => array (". gif ",". png ",". jpg ",". jpeg ",". bmp ") // allowed file format); // app_modedefined ('app _ mode') or define ('app _ mode', 'sa '); // upload the file directory $ Path = ".. /.. /uploads "; // Save the background to the temporary directory $ config [" savePath "] = $ Path; // form field/Configuration Parameter/Application Mode/storage domain name $ up = new Uploader ("upfile", $ config, APP_MODE, 'uploads '); $ type = $ _ REQUEST ['type']; $ callback = $ _ GET ['callback']; $ info = $ up-> getFileInfo (); /*** return data */if ($ callback) {echo 'script '. $ callback. '('. json_encode ($ info ). ') script';} else {echo json_encode ($ info );}