开发者

Uploaded photo results in "500 Internal Server Error" - PHP/IIS7/Windows Server 2008

I recently moved a website that was written for a LAMP environment to Windows Server 2008. I've managed to get just about everything working now, but I've got one last problem that I can't seem to solve.

I am letting the admin user upload a photo that will get resized to a large file and small file by the PHP script. Both files are getting uploaded perfectly but the large file won't display and will result in a "500 internal server error" when viewed?

I can log onto the server and open both the small and large file, but only the small file is showing on the website? I've copied the PHP script below but the permissions on both files seem to be the same.

I'm using PHP, IIS7 and Windows Server 2008. Hope someone can help,

Steven.

            // 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 . $im开发者_如何学Cage_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>';
        }


I know this questions was asked 4 years ago, but I just ran into this same problem, and thought I'd leave an answer for anyone who may come here later.

I found an answer here, but the basic premise is to modify the permissions of the temp folder that PHP initially uploads into. Allowing the IUSR account read access to the temp folder will allow them to view the file when it hits its final destination. Supposedly IIS7 will grant the permissions from the temp folder to the temporary upload file, which, when moved to your website directory, will keep those temp folder permissions.

Security-wise, you are allowing read access to your temp folder; so if you have sensitive information that ends up there at any point, you may have to find another solution.

A little more information can be found here


I got stuck into the same problem and i think this will help somebody

  1. Right-Click uploads directory / folder and select ‘Properties’
  2. Go to ‘Security’ tab
  3. Click Edit
  4. Select ‘IUSR’ under group or user names
  5. Select ‘Read & Execute’ under permissions for IUSR
  6. Click ‘Apply’ and ‘Ok’

Found this on http://wingedpost.org/2016/07/preventing-500-internal-server-error-uploaded-files-iis-php-sites/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜