我使用 apache2 提供一个允许上传文件的 php 页面
// Check if the file was uploaded
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$file = $_FILES['file'];
// Check for errors in the upload process
if ($file['error'] === UPLOAD_ERR_OK) {
// Define the target path in the /tmp directory
$targetPath = '/opt/upload/' . basename($file['name']);
// Move the uploaded file to the target path
if (move_uploaded_file($file['tmp_name'], $targetPath)) {
echo "File uploaded successfully to /tmp.";
} else {
echo "Failed to move the file to /tmp.";
}
} else {
echo "Error in file upload: " . $file['error'];
}
} else {
echo "No file uploaded.";
}
当我上传一个小文件时<8M, it works without a problem. However, when I try uploading a 3.4G file, it ends up in an error
文件上传错误:1
并且在日志中
tail -f /var/log/apache2/error.log
人们可以看到
[mpm_prefork:notice] AH00170: caught SIGWINCH, shutting down gracefully
[mpm_prefork:notice] AH00163: Apache/2.4.52 (Ubuntu) configured -- resuming normal operations
[core:notice] AH00094: Command line: '/usr/sbin/apache2'
我已经配置好了
post_max_size=20G
在加载的配置文件中
/etc/php/8.1/apache2/php.ini
。
发生什么事了?为什么我不能上传大文件而可以上传小文件?
我更改了以下附加配置并且它起作用了,感谢@Ken Lee 的有用评论。
upload_max_filesize = 20G
max_execution_time = 3600
max_input_time = 3600
memory_limit = 4G
说真的,StackOverflow 有那么毒吗?我询问了 chatGPT,它只对我有部分帮助,指出了
post_max_size
和 www-data
权限,以及 .htaccess
中的一些配置。没有其他资源,错误也很模糊。 Ken 的评论很容易解决了问题,有那么难吗?如果没有反馈和讨厌的评论,-1
有什么好处呢?我是会员7年了,积分都快5k了,不是不会英文的菜鸟