2017-04-19 255 views
0

我目前有一个与我有一个网络服务器的噩梦。我已经浏览了我可以找到的每个堆栈溢出页面,但仍然没有成功。无法上传大小超过1MB的文件 - PHP网络服务器

我有一个本地运行的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> 

这是我的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."; 
    } 
} 
?> 

这仅仅是基本的PHP图片上传从W3脚本学校 - 这是这个问题使我减少了!

我曾尝试:

  • 编辑php.ini文件然后重新启动阿帕奇
  • 更改HTML形式使得其包括ENCTYPE =“多部分/格式数据”的形式报头内
  • 添加htaccess来,其中的文件是
  • 改变上传脚本指定允许的最大图像尺寸的比特根www/html等文件夹:

我得到的错误是:

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

因此,您在本地服务器和主服务器上获得关于'getimagesize()'的错误?通过上传大于1 MB的文件获得_that_? –

+0

也许你超出了默认的时间限制,因为你的文件超过1MB。尝试使用'set_time_limit(0)'设置时间限制为无限制;' –

+0

不,我只在主服务器上有错误。当我在我的笔记本电脑上运行我的网络服务器时,只要将它推送到主服务器,一切都很好用。看着set_time_limit(0) - 我添加到php脚本但没有成功。 –

回答

0

您可以通过两种方式如下

我)在php.ini

ii)使用的ini_set( “upload_max_filesize的”, “30M”)更改的upload_max_filesize的值更改上传限制;

+0

你可以在哪里设置ini_set(“upload_max_filesize”,“30M”); ? –

+0

哦,从来没有想过,将其添加到php文件中,但无济于事 - 仍在寻找解决方案。 –

相关问题