【问题标题】:PHP File Upload Size IssuePHP 文件上传大小问题
【发布时间】:2015-10-21 03:36:28
【问题描述】:

我正在尝试使用 PHP 脚本上传 PDF 文件,以下是我的代码。它适用于任何小于 1 MB 的文件,但是当我上传超过 1 MB 时,它会转到 else 语句并给出以下消息 - “达到最大文件大小上传限制,请选择任何其他文件”。

我已经看过php.ini的配置了,这个是16M的。请帮忙

ini_set('upload_max_filesize', '16M');
            ini_set('post_max_size', '16M');
                //$ImageName=addslashes($_REQUEST['txtimagename']);
                //$ImageTitle=addslashes($_REQUEST['txtimagetitle']);
                $filepath="files/";
                
                //$filedt=date("dmYhisu")."_.".pathinfo($_FILES['imagefile']['name'], PATHINFO_EXTENSION);                                                      
                $filedt=$_POST['vehregistration'].".".pathinfo($_FILES['imagefile']['name'], PATHINFO_EXTENSION);
                
                //basename($_FILES['photoimg']['name']);
                $destination_img=$_POST['vehregistration'].".".pathinfo($_FILES['imagefile']['name'], PATHINFO_EXTENSION);
                
                
                
                $filename=$filepath.$destination_img;
                                    
                //$filename=$filepath.basename($_FILES['Photo']['name']);
                //echo "$filepath".$_FILES[" imagefile "][" name "];
                
                if(move_uploaded_file($_FILES["imagefile"]["tmp_name"], $filename))
                {
                    //echo $filedt;exit;
                    //rename($_FILES['Photo']['tmp_name'],$filedt);
                    
                    return $filedt;
                }
                else
                {

                            echo "Max File Size Upload Limit Reached, Please Select Any Other File";
                }   
            }

【问题讨论】:

  • print_r($_FILES)检查真实错误
  • 什么设置设置为 16M?您应该设置upload_max_filesize = 16M 以及post_max_size = 16M,因为您通过 POST 请求发送它

标签: php html


【解决方案1】:

在 else 条件下添加这个 $_FILES['imagefile']['error'] 看看什么是确切的错误。更多详情http://php.net/manual/en/features.file-upload.errors.php

【讨论】:

    【解决方案2】:

    而不是使用ini_set使用$_FILES["imagefile"]["size"]

    $fileSize = $_FILES["imagefile"]["size"]; // File size in bytes
    $maxFileSz = 16777216; // set your max file size (in bytes) in this case 16MB
    if($fileSize <= $maxFileSz) {
        // everything is okay... keep processing
    } else {
        echo 'Max File Size Upload Limit Exceeded, Please Select Any Other File';
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-08
      • 2013-05-07
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 1970-01-01
      相关资源
      最近更新 更多