我试图使用PHP://输入从PHP读取原始输入流.这适用于大多数文件,但是,上传时会忽略超过4MB的文件.我已经将post_max_size和upload_max_size设置为20M,每个人都认为它可以解决我的问题,但事实并非如此.是否有另一个需要配置的PHP.ini设置,或者我需要进行某种类型的分块?如果是这样,我该怎么做呢?这是upload.PHP代码:
- $fileName = $_SERVER['HTTP_X_FILE_NAME'];
- $contentLength = $_SERVER['CONTENT_LENGTH'];
- file_put_contents('uploads/' . $fileName,file_get_contents("PHP://input"));
尝试
stream_copy_to_stream
,它直接将输入的内容泵入文件,而不是先将其全部复制到内存中:
- $input = fopen('PHP://input','rb');
- $file = fopen($filename,'wb');
- stream_copy_to_stream($input,$file);
- fclose($input);
- fclose($file);
替代方案:
- $input = fopen('PHP://input','wb');
- while (!feof($input)) {
- fwrite($file,fread($input,102400));
- }
- fclose($input);
- fclose($file);