【问题标题】:PHP upload 14MB file failingPHP上传14MB文件失败
【发布时间】:2017-01-03 05:21:27
【问题描述】:

我正在尝试找出此上传脚本失败的原因。

从 HTML FORM 开始:

<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 语句之前和之后回显“hello”,但在第一个 IF 语句之后它就失败了。

【问题讨论】:

标签: php html upload


【解决方案1】:

您只需在php.ini 文件中增加upload_max_filesize 的值(默认为2M)(其位置取决于您的操作系统),然后重新启动您的网络服务器。

【讨论】:

  • 这是评论,并不是真正的答案
  • @HoodCoderMan 你重启你的网络服务器了吗?
猜你喜欢
  • 2012-07-24
  • 2023-04-02
  • 2011-05-04
  • 1970-01-01
  • 2023-01-22
  • 2012-04-12
  • 1970-01-01
  • 2013-12-17
  • 2012-01-07
相关资源
最近更新 更多