FileAction. class. php & lt ;? PhpclassFileActionextendsAction {functionindex () {$ fileM (& amp; #39; file & amp; #39;); $ list $ file-& gt; select (); $ this-& gt; assign (...
FileAction. class. php
- Class FileAction extends Action {
- Function index (){
- $ File = M ('file ');
- $ List = $ file-> select ();
- $ This-> assign ('filelist', $ list );
- $ This-> display ();
- }
- Function upload (){
- // Submit the file upload address to him. after the upload is complete, a message is returned for the file to be written to the database.
- If (emptyempty ($ _ FILES )){
- $ This-> error ('upload file is required ');
- } Else {
- $ A = $ this-> up ();
- If (isset ($ )){
- // Custom c method for writing data to the database
- If ($ this-> c ($ )){
- $ This-> success ('upload successful ');
- }
- Else {
- $ This-> error ('database writing failed ');
- }
- } Else {
- $ This-error ('file Upload exception, please contact the system Postmaster ');
- }
- }
- }
- Private function c ($ data ){
- $ File = M ('file ');
- $ Num = '0 ';
- For ($ I = 0; $ I <count ($ data)-1; $ I ++ ){
- $ Data ['filename'] = $ data [$ I] ['savename'];
- If ($ file-> data ($ data)-> add ())
- {
- $ Num ++;
- }
- }
- If ($ num = count ($ data)-1)
- {
- Return true;
- } Else
- {
- Return false;
- }
- }
- Private function up (){
- // Call the thinkphp-related file Upload class
- Import ('@. Org. uploadfile'); // Copy the upload class UploadFile. class. php to the Lib/Org folder.
- $ Upload = new UploadFile ();
- $ Upload-> maxSize = '000000'; // The default value is-1, which does not limit the upload size.
- $ Upload-> savePath = './Public/Upload/'; // The storage path is recommended to be saved in the same directory as the master file or in the same directory.
- $ Upload-> saveRule = uniqid; // rules for saving file names uploaded
- $ Upload-> uploadReplace = true; // whether to overwrite a file with the same name
- $ Upload-> allowExts = array ('jpg ', 'jpeg', 'PNG ', 'GIF'); // specifies the type of the file to be uploaded.
- $ Upload-> allowTypes = array ('image/png ', 'image/jpg', 'image/jpeg ', 'image/GIF'); // detect mime types
- $ Upload-> thumb = true; // whether to enable image file thumbnails
- $ Upload-> thumbMaxWidth = '000000 ';
- $ Upload-> thumbMaxHeight = '000000 ';
- $ Upload-> thumbPrefix ='s _, m _ '; // prefix of the thumbnail file
- $ Upload-> thumbRemoveOrigin = 1; // whether to delete the source image if a thumbnail is generated
- If ($ upload-> upload ()){
- $ Info = $ upload-> getUploadFileInfo ();
- Return $ info;
- } Else {
- $ This-> error ($ upload-> getErrorMsg (); //
- }
- }
- }
- ?>
Template file index.html
-
-
-
-
- Thumbnail:
- Big chart:
-
-
-
-
-
-
-
-
-
-