【问题标题】:Uploaded photo results in "500 Internal Server Error" - PHP/IIS7/Windows Server 2008上传的照片导致“500 内部服务器错误” - PHP/IIS7/Windows Server 2008
【发布时间】:2011-03-13 17:44:19
【问题描述】:

我最近将一个为 LAMP 环境编写的网站迁移到了 Windows Server 2008。我现在已经设法让几乎所有东西都能正常工作,但最后一个问题似乎无法解决。

我让管理员用户上传一张照片,该照片将通过 PHP 脚本调整为大文件和小文件。两个文件都已完美上传,但大文件无法显示,查看时会导致“500 内部服务器错误”?

我可以登录服务器打开小文件和大文件,但网站上只显示小文件?我已经复制了下面的 PHP 脚本,但两个文件的权限似乎是相同的。

我正在使用 PHP、IIS7 和 Windows Server 2008。希望有人能提供帮助,

史蒂文。

            // only process if the first image has been found
        if(isset($image_file)) {
            // get photo attributes
            $image_filename = $image_file['name'];
            $image_temp = $image_file['tmp_name'];
            $image_ext = substr($image_filename,strpos($image_filename,'.'),strlen($image_filename)-1);

            // validate photo attributes
            if(strtolower($image_ext) == '.jpg' && filesize($image_temp) <= 4194304) {
                // create custom timestamp
                $image_timestamp = date('dmYHis');

                // clean up filename
                $image_filename = trim(str_replace('\'','',$image_filename));
                $image_filename = str_replace('\\','',$image_filename);
                $image_filename = str_replace('&','',$image_filename);
                $image_filename = str_replace(' ','-',$image_filename);

                // set file names
                $image_large_file = strtolower($image_timestamp . '-large-1-' . $image_filename);
                $image_small_file = strtolower($image_timestamp . '-thumb-1-' . $image_filename);

                // image url source
                $image_source = $_SERVER['DOCUMENT_ROOT'] . '/images/';

                // upload image file
                if(move_uploaded_file($image_temp,$image_source . $image_large_file)) {
                    // resize, save & destroy LARGE image
                    list($image_width,$image_height) = getimagesize($image_source . $image_large_file);
                    $image_container = imagecreatetruecolor(420,315);
                    $image_temp = imagecreatefromjpeg($image_source . $image_large_file);
                    imagecopyresampled($image_container,$image_temp,0,0,0,0,420,315,$image_width,$image_height);
                    imagejpeg($image_container,$image_source . $image_large_file,75);
                    imagedestroy($image_container);

                    // resize, save & destroy SMALL image
                    list($image_width,$image_height) = getimagesize($image_source . $image_large_file);
                    $image_container = imagecreatetruecolor(90,68);
                    $image_temp = imagecreatefromjpeg($image_source . $image_large_file);
                    imagecopyresampled($image_container,$image_temp,0,0,0,0,90,68,$image_width,$image_height);
                    imagejpeg($image_container,$image_source . $image_small_file,100);
                    imagedestroy($image_container);
                }
                else
                    $status = '<h3 class="red">Sorry, but there was a problem uploading one of the images to the server</h3>';
            }
            else
                $status = '<h3 class="red">Please check that all the image size\'s are less than 4MB and they\'re all in JPG format</h3>';
        }

【问题讨论】:

  • IIS 有错误日志,不是吗? 500 错误代码几乎可以保证您的答案会出现在该错误日志中。
  • 可能错误类似于 Call to undefined function imagecreatetruecolor()

标签: php iis-7 windows-server-2008


【解决方案1】:

我知道这个问题是 4 年前提出的,但我刚刚遇到了同样的问题,并认为我会为以后可能来这里的任何人留下答案。

I found an answer here,但基本前提是修改PHP最初上传到的temp文件夹的权限。允许 IUSR 帐户读取临时文件夹的权限将允许他们在文件到达最终目的地时查看文件。假设 IIS7 会将临时文件夹中的权限授予临时上传文件,当移动到您的网站目录时,将保留这些临时文件夹权限。

安全方面,您允许读取临时文件夹;因此,如果您的敏感信息在任何时候都会出现,您可能必须找到另一种解决方案。

更多信息可以找到here

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,我认为这会对某人有所帮助

    1. 右键单击上传目录/文件夹并选择“属性”
    2. 转到“安全”标签
    3. 点击编辑
    4. 在组或用户名下选择“IUSR”
    5. 在 IUSR 权限下选择“读取和执行”
    6. 点击“应用”和“确定”

    http://wingedpost.org/2016/07/preventing-500-internal-server-error-uploaded-files-iis-php-sites/找到这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2013-08-11
      • 2012-03-29
      相关资源
      最近更新 更多