gpt4 book ai didi

PHP 上传 14MB 文件失败

转载 作者:可可西里 更新时间:2023-11-01 01:15:48 25 4
gpt4 key购买 nike

我想弄清楚为什么这个上传脚本失败了。

从 HTML 表单开始:

<form role="form" action="api/upload.php" method="post" enctype="multipart/form-data">
<input id="file" name="file" type="file" />
<input class="btn btn-primary" type="submit" value="Upload" />
</form>

这是 PHP 脚本:

<?php
if(isset($_FILES['file'])){
$file = $_FILES['file'];
$target_file = basename($_FILES["file"]["name"]);

$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];

$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));

$allowed = array('txt', 'jpg', 'xlsx', 'pptx', 'docx', 'doc', 'xls', 'pdf');

if(in_array($file_ext, $allowed)){
if($file_error === 0){
if($file_size <= 99600000){ // this was set to 600000
$file_name_new = uniqid('', true) . '.' . $file_ext;
$file_destination = '../files/' . $file_name;

if(move_uploaded_file($file_tmp, $file_destination)){
header("Location: ../index.php");
die();
}
else{
echo "There was a problem uploading the file";
}
}
else{
echo "The file is too large";
}
}
else{
echo "There was an error uploading the file";
}
}
else{
echo "The file type is not allowed";
}
}
?>

请原谅嵌套的 IF 语句。我在 youtube 上关闭了这个视频:https://www.youtube.com/watch?v=PRCobMXhnyw

上面的代码有效。我可以上传文件,当发生错误时,我会收到相应的错误消息。

但是,我遇到了无法上传的文件。这是一个允许的文件,一个 word 文档,恰好是 14MB。不确定这是否太大。但即便如此,我尝试上传的太大的文件仍无法通过 file_size 检查,并且我会收到相应的错误消息。

在这种情况下,我得到的只是一个空白屏幕。我可以在初始 IF 语句之前和之后回显“你好”,但它在第一个 IF 之后立即失败。

最佳答案

您应该简单地增加 upload_max_filesize 的值(默认情况下它是 2M)在你的 php.ini 文件中(它的位置取决于你的操作系统),然后重新启动你的网络服务器。

关于PHP 上传 14MB 文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39167937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com