Home Backend Development PHP Tutorial php 图片上传 500 Internal Server Error 错误

php 图片上传 500 Internal Server Error 错误

Jun 20, 2016 pm 12:53 PM

写php简单上传图片时,发现200k的图片上传时报Internal Server Error错误,检查了 upload_max_filesize,及其他post_max_size、max_input_time、memory_limit、 max_execution_time配置项均没有问题,后检查错误日 志:mod_fcgid: HTTP request length 138296 (so far) exceeds MaxRequestLen (131072), 发现问题所在。

原 来是fastcgi模式下的设置问题,看上去是因为HTTP刚才的请求长度(138296 )太长,大于现有的131072最大请求长度。看了fcgid 的配置文件后,发现并没有配置过MaxRequestLen的参数。看来这个131072的配置是默认的了。于是在fcgid的配置文件里加入这个配 置,15728640是15M,因为我的php.ini中设置的最大POST长度是15M,所以把它们设置长一样 的:MaxRequestLen 15728640

MaxRequestLen 15728640

AddHandler fcgid-script .fcgi .php

# Where to look for the php.ini file?

FcgidInitialEnv PHPRC        ”e:/wamp/bin/apache/apache2.3.14/bin”

# Set PHP_FCGI_MAX_REQUESTS to greater than or equal to FcgidMaxRequestsPerProcess

# to prevent php-cgi process from exiting before all requests completed

FcgidInitialEnv PHP_FCGI_MAX_REQUESTS      1000

# Maximum requests a process should handle before it is terminated

FcgidMaxRequestsPerProcess                 1000

# Maximum number of PHP processes

FcgidMaxProcesses                          15

# Number of seconds of idle time before a php-cgi process is terminated

FcgidIOTimeout                             120

FcgidIdleTimeout                           120

#Path to php-cgi

FcgidWrapper ”e:/wamp/bin/php/php5.4/php-cgi.exe” .php

# Define the MIME-Type for ”.php” files

AddType application/x-httpd-php .php

里面的“MaxRequestLen”就是fastcgi模式下上传文件也就是http接受的最大文件长度。

问题解决

 

注:

PHP默认的上传限定是最大2M,想上传超过此设定的文件,需要调整PHP、apache等的一些参数。下面,我们简要介绍一下PHP文件上传涉及到的一些参数:

file_uploads 

:是否允许通过HTTP上传文件的开关,默认为ON即是开。

upload_tmp_dir 

:upload_tmp_dir用来说明PHP上传的文件放置的临时目录,要想上传文件,得保证服务器没有关闭临时文件和有对文件夹的写权限,如果未指定则PHP使用系统默认值。

upload_max_filesize 

:允许上传文件大小的最大值,默认为2M。

post_max_size 

:控制在采用POST方法进行一次表单提交中PHP所能够接收的最大数据量。如果希望使用PHP文件上传功能,则需要将此值改为比upload_max_filesize要大。

max_input_time 

:以秒为单位对通过POST、GET以及PUT方式接收数据时间进行限制。如果应用程序所运行环境处在低速链路上,则需要增加此值以适应接收数据所需的更多时间。

memory_limit 

:为了避免正在运行的脚本大量使用系统可用内存,PHP允许定义内存使用限额。通过memory_limit变量来指定单个脚本程序可以使用的最大内存容量变量memory_limit的值应当适当大于post_max_size的值。

max_execution_time 

:max_execution_time 设置了在强制终止脚本前PHP等待脚本执行完毕的时间,此时间以秒计算。当脚本进入了一个无限循环状态时此变量非常有用。然而,当存在一个需要很长时间完 成的合法活动时(例如上传大型文件),这项功能也会导致操作失败。在这样的情况下必须考虑将此变量值增加,以避免PHP在脚本正在执行某些重要过程的时候 将脚本关闭。

对于linux主机,可能在/etc/httpd/conf.d/access.conf/下面里面还有php.conf 文件,这个文件可能会解决一些系统的文件大小限制问题。


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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles