多个图像上传导致500内部服务器错误 [英] Multiple image uploads cause 500 Internal Server Error

查看:109
本文介绍了多个图像上传导致500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上实现多个部分,访问者可以上传他们的图像进行显示。
我让它在服务器上的测试文件夹中完美地工作,它回应文件是图像。[文件]成功上传,图像出现在服务器上。

I want to implement multiple sections on my website, where visitors can upload their images to be shown. I got it to work perfectly in a test folder on the server, where it echoes "File is an image. [file] succesfully uploaded" and the image appears on the server.

然而,随着这个脚本实际实现到网站(我将脚本复制到另一个文件夹),我得到了返回:500内部服务器错误。

However, with the actual implementation of this script into the website (I copied the scripts to a different folder), I get returned: 500 Internal Server error.

你们中有谁知道会导致这个问题的原因吗?

Does anyone of you know what could cause this issue?

HTML表格(在/entries.php中):

The HTML form (in /entries.php):

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <link href="../../style.css" rel="stylesheet" type="text/css">
    </head>
    <body bgcolor="#000000">    
        <form action="upload.php" method="post" enctype="multipart/form-data"><p class="text">
            Upload your entry here!:
            <input type="file" name="fileToUpload" id="fileToUpload">
            <input type="submit" value="Upload Image" name="submit"></p>
        </form>
    </body>
</html>

PHP脚本(在upload.php中):

The PHP script (in upload.php):

<?php
$target_dir = "images/";
$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"] > 500000) {
    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.";
    }
}
?>


推荐答案

upload_max_filesize



upload_max_filesize in the php.ini may need to be increased.

echo ini_get ("upload_max_filesize");

此命令将为您提供值,然后您可以进入php.ini并增加它不够。



This command will give you the value, then you can go into your php.ini and increase it if not sufficient.

在这种情况下,您可以在httpd.conf中创建一个类似于以下内容的新apache指令。

In this case you can create a new apache directive in your httpd.conf similar to the following.

FcgidMaxRequestLen bytes

FcgidMaxRequestLen bytes

<IfModule mod_fcgid.c>
    MaxRequestLen 15728640
</IfModule>


由于每个托管公司的配置不同,因此流程可能会有所不同。但这是GoDaddy和Plesk的流程。

Since each hosting company has a different configuration the process may vary. But here is the process for GoDaddy and Plesk.

我可以在运行Parallels Plesk Panel的服务器上使用open_basedir吗?



Can I use open_basedir on my server running Parallels Plesk Panel?

您需要将其从PHP脚本所在的目录以及文件上载的目录中移出。如果这允许上传显然你知道.htaccess中有一个规则/指令导致问题。

You'll want to move it from the directory where your PHP script resides, and the directory where your files are uploading. If this allows uploads obviously you know there's a rule/directive in the .htaccess causing the issue.

这篇关于多个图像上传导致500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆