Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法上载大小超过1MB的文件-PHP Web服务器_Php_Html_Apache_.htaccess_Mod Security - Fatal编程技术网

无法上载大小超过1MB的文件-PHP Web服务器

无法上载大小超过1MB的文件-PHP Web服务器,php,html,apache,.htaccess,mod-security,Php,Html,Apache,.htaccess,Mod Security,我现在有一个网站服务器让我有点噩梦。我几乎搜索了我能找到的每一个堆栈溢出页面,但仍然没有成功 我有一个在本地运行的Web服务器,我会先在上面测试这些设置,一切正常,但每当我将相同的设置应用到我的主服务器时,就没有这样的运气了 通过使用简单的html页面和php页面来处理请求,我已经回到了基础,但是如果超过1MB,仍然会失败 作为参考,这是我的html脚本: <!DOCTYPE html> <html> <body> <form

我现在有一个网站服务器让我有点噩梦。我几乎搜索了我能找到的每一个堆栈溢出页面,但仍然没有成功

我有一个在本地运行的Web服务器,我会先在上面测试这些设置,一切正常,但每当我将相同的设置应用到我的主服务器时,就没有这样的运气了

通过使用简单的html页面和php页面来处理请求,我已经回到了基础,但是如果超过1MB,仍然会失败

作为参考,这是我的html脚本:

<!DOCTYPE html>
    <html>
    <body>

    <form action="test.php" method="post" enctype="multipart/form-data">
        Select image to upload:
        <input type="file" name="fileToUpload" id="fileToUpload">
        <input type="submit" value="Upload Image" name="submit">
    </form>

    </body>
</html>
有人能帮我吗?我也尝试过禁用mod_安全性,但在我的apache2服务器上都找不到


非常感谢

您可以通过以下两种方式更改上载限制

i) 更改php.ini中upload_max_filesize的值


ii)使用ini_集(“上传最大文件大小”,“30M”)

您可以通过以下两种方式更改上载限制

i) 更改php.ini中upload_max_filesize的值


ii)使用ini_集(“上传最大文件大小”,“30M”)

那么,您在本地服务器和主服务器上都遇到了关于
getimagesize()
的错误吗?通过上传大于1MB的文件可以得到这个结果?可能你超过了默认的时间限制,因为你的文件超过1MB。尝试使用
set\u time\u limit(0)将时间限制设置为无限否,我只有主服务器上的错误。当我在笔记本电脑上运行的Web服务器上试用它时,一切都很好,就在我把它推到主服务器上的时候。查看set_time_limit(0)-我将其添加到php脚本中,但没有成功。因此,在本地服务器和主服务器上都出现了关于
getimagesize()
的错误吗?通过上传大于1MB的文件可以得到这个结果?可能你超过了默认的时间限制,因为你的文件超过1MB。尝试使用
set\u time\u limit(0)将时间限制设置为无限否,我只有主服务器上的错误。当我在笔记本电脑上运行的Web服务器上试用它时,一切都很好,就在我把它推到主服务器上的时候。查看set_time_limit(0)-我将其添加到php脚本中,但没有成功。您可以在哪里设置ini_set(“upload_max_filesize”,“30M”)?哦,没关系,也把它添加到了php文件中,但是没有用——仍然在寻找解决方案。您可以在哪里设置ini_set(“upload_max_filesize”,“30M”)?哦,没关系,也把它添加到了php文件中,但是没有用——仍然在寻找解决方案。
<?php
$target_dir = "";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 8000000) { //8mb
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>
Warning: getimagesize(): Filename cannot be empty in /var/www/html/test.php on line 8
File is not an image.Sorry, your file was not uploaded.