Table of Contents
1. Mac Auto Configuring php.ini in a PHP environment
2. Modify the php.ini configuration file in XAMPP For Mac
附:修改PHP上传文件大小限制的方法
1. 一般的文件上传,除非文件很小.就像一个5M的文件,很可能要超过一分钟才能上传完.
2. 修改 post_max_size 设定 POST 数据所允许的最大大小。此设定也影响到文件上传。
3. 很多人都会改了第二步.但上传文件时最大仍然为 8M.
Home Backend Development PHP Problem php modify configuration file

php modify configuration file

Nov 18, 2020 am 09:38 AM
php.ini

How to modify the configuration file of php: first find and open the php.ini configuration file; then find the "max_execution_time" item in the file; finally modify the parameters and save it.

php modify configuration file

The operating environment of this tutorial: MacOS X system, php5.6. This article is applicable to all brands of computers.

Recommended: "PHP Video Tutorial"

1. Mac Auto Configuring php.ini in a PHP environment

There is no default php.ini file in Mac OS X, but there is a corresponding template file php.ini.default, located at /private/etc/php.ini.default or Say /etc/php.ini/default, you can make a copy and modify it yourself.
Copy command:

sudo cp /private/etc/php.ini.default /private/etc/php.ini
Copy after login

After successful copying

cd /private/etc/sudo vi php.ini
Copy after login

2. Modify the php.ini configuration file in XAMPP For Mac

Modify the php.ini configuration file during installation Directory/Applications/XAMPP/xamppfiles/etc/php.ini

file_uploads=on/offWhether it is allowed to upload files via http
max_execution_time=30The maximum execution time allowed for the script, if it exceeds this time, an error will be reported
memory_limit=50MSet the maximum amount of memory that a script can allocate to prevent runaway scripts from occupying too much memory. This instruction only takes effect when the –enable-memory-limit flag is set during compilation.
upload_max_filesize=20MThe maximum size of files allowed to be uploaded, this command must be smaller than post_max_size
upload_tmp_dirThe temporary storage directory for uploaded files
post_max_size=30MAllow the post method to accept the maximum size

$_FILES array content is as follows:

$_FILES['myFile']['name']The original name of the client's last file
$_FILES['myFile']['type']The MIME type of the file, the browser needs to provide support for this information, such as "image/gif"
$_FILES['myFile']['size']The size of the uploaded file in bytes
$_FILES['myFile'] ['tmp_name']The temporary file name stored on the server after the file is uploaded, usually the system default. It can be specified in upload_tmp_dir of php.ini, but setting it with the putenv() function will not work
$_FILES['myFile']['error']Status code related to the file upload

$_FILES['myFile']['error']Status code related to the file upload . [‘error’] was added in PHP version 4.2.0. The following is its description: (They became constants after PHP3.0)

UPLOAD_ERR_OK Value: 0No error occurred, the file was uploaded successfully
UPLOAD_ERR_INI_SIZE value: 1The uploaded file exceeds the value limited by the upload_max_filesize option in php.ini
UPLOAD_ERR_FORM_SIZE value: 2The size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form
UPLOAD_ERR_PARTIAL value: 3Only part of the file was uploaded
UPLOAD_ERR_NO_FILE Value: 4No file was uploaded
Value: 5The uploaded file size is 0

文件被上传结束后,默认地被存储在了临时目录中,这时您必须将它从临时目录中删除或移动到其它地方,如果没有,则会被删除。

也就是不管是否上传成功,脚本执行完后临时目录里的文件肯定会被删除。

附:修改PHP上传文件大小限制的方法

1. 一般的文件上传,除非文件很小.就像一个5M的文件,很可能要超过一分钟才能上传完.

但在php中,默认的该页最久执行时间为 30 秒.就是说超过30秒,该脚本就停止执行.

这就导致出现 无法打开网页的情况.这时我们可以修改 max_execution_time

在php.ini里查找

max_execution_time
Copy after login

默认是30秒.改为

max_execution_time = 0
Copy after login

0表示没有限制

2. 修改 post_max_size 设定 POST 数据所允许的最大大小。此设定也影响到文件上传。

php默认的post_max_size 为2M.如果 POST 数据尺寸大于 post_max_size $_POST$_FILES superglobals 便会为空.

查找 post_max_size .改为

post_max_size = 150M
Copy after login

3. 很多人都会改了第二步.但上传文件时最大仍然为 8M.

为什么呢.我们还要改一个参数upload_max_filesize 表示所上传的文件的最大大小。

查找upload_max_filesize,默认为8M改为

upload_max_filesize = 100M
Copy after login

       另外要说明的是,post_max_size 大于 upload_max_filesize 为佳

The above is the detailed content of php modify configuration file. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to turn off cache in php.ini How to turn off cache in php.ini Mar 15, 2021 am 09:35 AM

How to turn off the cache in php.ini: 1. Find and open the php.ini configuration file; 2. Find the "opcache.enable" and "opcache.enable_cli" options and modify them to "opcache.enable=0" and "opcache. enable_cli=0”; 3. Save the modified file.

Let's talk about how to modify the php.ini configuration file Let's talk about how to modify the php.ini configuration file Mar 28, 2023 pm 05:34 PM

PHP.ini is a PHP configuration file that is used to control the performance of PHP on the server. This file is used to set the values ​​of some variables to control PHP at runtime. This article will show you how to modify the PHP.ini configuration file to control how PHP behaves on your server.

[Compilation and Summary] Common PHP.ini prompt errors and solutions [Compilation and Summary] Common PHP.ini prompt errors and solutions Mar 20, 2023 pm 04:56 PM

PHP is a commonly used server-side scripting language that is widely used in the field of web development. However, during the PHP development process, we often encounter various problems. Among them, PHP.ini prompt error is a common problem.

How to change time zone in php.ini file How to change time zone in php.ini file Mar 22, 2023 pm 03:22 PM

PHP is a very popular server-side programming language. When developing web applications using PHP, we sometimes need to set the time zone in PHP. The default time zone of PHP is "UTC (Coordinated Universal Time)", which is not the time zone we want in many cases, so we need to change the time zone setting in the php.ini file. This article will explain how to change the time zone in the php.ini file.

How to solve the problem that linux php.ini does not take effect How to solve the problem that linux php.ini does not take effect May 13, 2023 am 09:10 AM

Solution to linuxphp.ini not taking effect: 1. Reload the php.ini configuration file; 2. Search for the configuration to be modified in the printed "phpinfo();"; 3. View the "php-fpm.conf" configuration file , check whether the configuration in php.ini is overwritten. What should I do if linuxphp.ini does not take effect? Troubleshooting the problem that modifying php.ini does not take effect in the Linux environment. The main reasons why php.ini does not take effect after modification are as follows: 1. After modifying the php.ini configuration file, the php.ini configuration file is not reloaded. 2. There are multiple php.ini configuration files. 3. The configuration in php.ini is included in other files.

How to modify the php.ini file in wamp How to modify the php.ini file in wamp Mar 20, 2023 pm 03:33 PM

Wampserver is a software package that can install Apache, PHP and MySQL on Windows computers. Develop and test PHP websites on your local computer easily with Wampserver. During the development process, we may need to modify the PHP configuration file php.ini. This article will introduce how to modify the php.ini file in Wampserver.

How to solve the problem that there is no mysql.all in php7 php.ini How to solve the problem that there is no mysql.all in php7 php.ini May 28, 2023 am 11:59 AM

Migration issues in PHP7 PHP7 is the next major version of PHP. It has huge improvements in performance and security, so many websites hope to upgrade to PHP7 as soon as possible. However, upgrading to PHP7 is not always easy. Due to incompatibilities with previous versions, enterprises may need to make some modifications, usually in the application code and in the PHP configuration files. As mentioned above, the mysql extension in PHP7 has been removed, so if you were using the mysql extension in an older version of PHP, you will need to make some modifications when migrating to PHP7. You can choose to replace the mysql extension with the mysqli extension (mysqli is the "MySQLImproved" extension

What should I do if changing php.ini in php7 does not work? What should I do if changing php.ini in php7 does not work? Nov 07, 2022 am 09:54 AM

Solution to the problem that changing php.ini in php7 does not work: 1. Check the path of the configuration file; 2. Modify the parameters of "php.ini" under windows; 3. Set the parameter of "post_max_size" to N of "upload_max_filesize" times; 4. Restart apache.

See all articles