PHP文件上载大小问题

时间:2015-10-21 03:36:28

标签: php html

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

我已经看过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";
                }   
            }

提前致谢

2 个答案:

答案 0 :(得分:0)

而不是使用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';
}

快乐的编码!

答案 1 :(得分:0)

在else条件$_FILES['imagefile']['error']中添加此内容并查看确切错误。有关详细信息http://php.net/manual/en/features.file-upload.errors.php