php输入流大小限制 [英] php input stream size limitations
问题描述
我正在尝试使用php://input从php读取原始输入流.这适用于大多数文件,但是在上传中,文件大小超过4MB的文件将被忽略.我分别将post_max_size和upload_max_size设置为20M,以为它可以解决我的问题,但事实并非如此.是否有另一个php.ini设置需要配置,还是我需要进行某种形式的分块?如果是这样,我将如何去做?这是upload.php代码:
I am trying to read a raw input stream from php using php://input. This works for most files, however, files over 4MB are being ignored in the upload. I have set post_max_size and upload_max_size to 20M each thinking it would solve my problem, but it didn't. Is there another php.ini setting that needs to be configured or do I need to do chunking of some sort? If so, how would I go about doing that? Here is the upload.php code:
$fileName = $_SERVER['HTTP_X_FILE_NAME'];
$contentLength = $_SERVER['CONTENT_LENGTH'];
file_put_contents('uploads/' . $fileName, file_get_contents("php://input"));
推荐答案
尝试 stream_copy_to_stream
,它将输入的内容直接泵送到文件中,而无需先将其全部复制到内存中:
Try stream_copy_to_stream
, which directly pumps the content of the input into the file without copying it all into memory first:
$input = fopen('php://input', 'rb');
$file = fopen($filename, 'wb');
stream_copy_to_stream($input, $file);
fclose($input);
fclose($file);
替代:
Alternative:
$input = fopen('php://input', 'rb');
$file = fopen($filename, 'wb');
while (!feof($input)) {
fwrite($file, fread($input, 102400));
}
fclose($input);
fclose($file);
这篇关于php输入流大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!