Is there a question about the Upload class in thinkphp3.2.3?

Source: Internet
Author: User
{Code ...} this class puts all the configurations in this array attribute during initialization. However, when reading the official documentation, I can set these configurations by calling class attributes, example: {code ...} I don't understand it here. this maxSize is only the config array...
Private $ config = array ('mimes '=> array (), // The MiMe type of the file that can be uploaded 'maxsize' => 0, // the size of the uploaded file is limited (0-No limit) 'exts' => array (), // The suffix of the file to be uploaded is 'autosub' => true, // the automatic subdirectory saves the file 'subname' => array ('date', 'Y-m-D'), // The subdirectory creation method, [0]-function name, [1]-parameter. multiple parameters use the array 'rootpath' => '. /Uploads/', // Save the root path 'savepath' => '', // Save the path 'savename' => array ('uniqid ',''), // upload file naming rule, [0]-function name, [1]-parameter, multiple parameters use array 'savext' => '', // Save the suffix of the file, if it is null, use the original suffix 'replace '=> false, // whether the same name overwrites 'hash' => true, // whether to generate the hash code 'callback' => false, // check whether a file callback exists. If an array of returned file information is 'driver '=> '', // The file Upload driver 'driverconfig' => array (), // Upload driver configuration); public function _ construct ($ config = array (), $ driver = '', $ driverConfig = null) {/* Get configuration */$ this-> config = array_merge ($ this-> config, $ config );}

This class puts all the configurations in this array attribute during initialization. However, when reading the official documentation, I can set these configurations by calling class attributes, for example:

$ Upload = new \ Think \ Upload (); // instantiate the upload class $ upload-> maxSize = 3145728; // Set the attachment Upload size

I don't understand it here. this maxSize is just a subscript in the config array attribute. it should be assigned a value like $ upload-> config ['maxsize, how can I assign values directly using attributes ??

Reply content:
Private $ config = array ('mimes '=> array (), // The MiMe type of the file that can be uploaded 'maxsize' => 0, // the size of the uploaded file is limited (0-No limit) 'exts' => array (), // The suffix of the file to be uploaded is 'autosub' => true, // the automatic subdirectory saves the file 'subname' => array ('date', 'Y-m-D'), // The subdirectory creation method, [0]-function name, [1]-parameter. multiple parameters use the array 'rootpath' => '. /Uploads/', // Save the root path 'savepath' => '', // Save the path 'savename' => array ('uniqid ',''), // upload file naming rule, [0]-function name, [1]-parameter, multiple parameters use array 'savext' => '', // Save the suffix of the file, if it is null, use the original suffix 'replace '=> false, // whether the same name overwrites 'hash' => true, // whether to generate the hash code 'callback' => false, // check whether a file callback exists. If an array of returned file information is 'driver '=> '', // The file Upload driver 'driverconfig' => array (), // Upload driver configuration); public function _ construct ($ config = array (), $ driver = '', $ driverConfig = null) {/* Get configuration */$ this-> config = array_merge ($ this-> config, $ config );}

This class puts all the configurations in this array attribute during initialization. However, when reading the official documentation, I can set these configurations by calling class attributes, for example:

$ Upload = new \ Think \ Upload (); // instantiate the upload class $ upload-> maxSize = 3145728; // Set the attachment Upload size

I don't understand it here. this maxSize is just a subscript in the config array attribute. it should be assigned a value like $ upload-> config ['maxsize, how can I assign values directly using attributes ??

Magic method _ set (): when assigning values to inaccessible properties, __set () is called.

Look at the _ set () method in the class...

/*** Use $ this-> name to obtain the configuration * @ param string $ name configuration name * @ return multitype configuration value */public function _ get ($ name) {return $ this-> config [$ name];} public function _ set ($ name, $ value) {if (isset ($ this-> config [$ name]) {$ this-> config [$ name] = $ value; if ('driverconfig' = $ name) {// reset the upload driver after changing the driver configuration // Note: You must change the driver configuration and then change the driver configuration $ this-> setDriver ();}}}

Look, these two magic methods re-implement class attribute access and operations;
In this way, the seemingly class attribute $ config is an array, but you can use these two magic methods to specify each element in the class attribute $ config as its own KEY as its class property name, VALUE is a class property VALUE.

If you do not rewrite the two magic methods, you may be able to understand them in another way:

/*** Default upload configuration * @ var array */$ mimes = array (); // The MiMe type of the file to be uploaded $ maxSize = 0; // the size of the uploaded file is limited (0-No limit) $ exts = array (); // the suffix of the file to be uploaded $ autoSub = true; // automatic subdirectory save file $ subName = array ('date', 'Y-m-D'); // subdirectory creation method, [0]-function name, [1]-parameter. multiple parameters use an array $ rootPath = '. /Uploads/'; // Save the root path $ savePath = ''; // Save the path $ saveName = array ('uniqid',''); // upload file naming rules, [0]-function name, [1]-parameter. multiple parameters use the array $ saveExt = ''; // Save the file suffix. if it is null, use the original suffix $ replace = false; // whether the same name overwrites $ hash = true; // whether to generate the hash code $ callback = false; // checks whether the file has a callback, if an array of returned file information $ driver = ''; // file Upload driver $ driverConfig = array (); // Upload driver configuration

It only involves the special attributes of the $ driverConfig class. This is not the scope of your issue.

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.