When using the thinkphp framework to develop projects, we may find that by default the framework limits the size of uploaded files, the size of form submission data, and the number of sql query results. This is useful for those who need to upload large files or query big data. It will cause a lot of trouble for large-scale projects. Therefore, we need to modify and remove these default restrictions.
In the thinkphp framework, the upload file size limit is implemented by upload_max_filesize and post_max_size in php.ini, so we need Modify these two configuration items in the php.ini file.
First, enter php --ini on the command line to view the path to the php.ini file. Find the file and open it, and then modify it as follows:
upload_max_filesize = 100M
post_max_size = 100M
100M can be adjusted according to project needs. After the modification is completed, save and restart the Apache or Nginx server.
In the thinkphp framework, the form submission data size limit is implemented by post_max_size and memory_limit in php.ini, similarly Modifications are required. Find these two configuration items in the php.ini file and make the following modifications:
post_max_size = 100M
memory_limit = 128M
100M can be adjusted according to project needs. After the modification is completed, save and restart the Apache or Nginx server.
In the thinkphp framework, the limit on the number of sql query results is set by the framework itself, so the framework code needs to be modified to modify.
In the core code file ThinkPHPDbDriverPdo.php of the thinkphp framework, you can find the following code:
if (isset($options['limit'])) {
$limit = is_numeric($options['limit']) ? $options['limit'] : 100000; $this->_queryStr .= ' LIMIT ' . $limit;
}
100000 is the default limit on the number of query results. We can modify it to a larger value or change it to 0 to indicate no limit on the number of items. After the modification is completed, save and re-run the project.
Summary
By modifying the php.ini configuration file and thinkphp framework code, we can remove the default restrictions and solve some problems in projects that upload large files or query large amounts of data. It should be noted that when modifying the configuration file, it should be adjusted according to specific needs, and do not set too large a value that will cause excessive burden on the server.
The above is the detailed content of thinkphp removes default restrictions. For more information, please follow other related articles on the PHP Chinese website!