我目前正在使用我拥有的网络服务器做一些噩梦。我已经搜索了我能找到的每个Stack Overflow页面,但仍然没有成功。
我有一个本地运行的网络服务器,我会首先测试这些设置,一切正常,但每当我将相同的设置应用到我的主服务器时,都没有运气。
我只是通过使用一个简单的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>
这是我处理请求的test.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.";
}
}
?>
这只是来自w3学校的基本php图片上传脚本 - 这就是这个问题让我减少了!
我尝试过:
我得到的错误是:
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.
任何人都可以帮助我吗?我也尝试过调试禁用mod_security,但我甚至无法在我的apache2服务器上找到它。
非常感谢。
答案 0 :(得分:0)
您可以通过以下两种方式更改上传限制
i)在php.ini
中更改upload_max_filesize的值ii)使用ini_set(&#34; upload_max_filesize&#34;,&#34; 30M&#34;);