• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

PHP Script won't dispaly the mime type text/html

I have a php script that is to display random images and/or html pages. I cannot get the html pages to display. I get a Red X and nothing disaplys. All of the image file types work fine.
<?php
 
	$folder = 'Shenanigans/Main Page';
 
 
    $extList = array();
	$extList['gif'] = 'image/gif';
	$extList['jpg'] = 'image/jpeg';
	$extList['jpeg'] = 'image/jpeg';
	$extList['png'] = 'image/png';
	$extList['htm'] = 'text/html';
	$extList['html'] = 'text/html';
 
 
 
$img = null;
 
if (substr($folder,-1) != '/') {
	$folder = $folder.'/';
}
 
if (isset($_GET['img'])) {
	$imageInfo = pathinfo($_GET['img']);
	if (
	    isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
		$img = $folder.$imageInfo['basename'];
	}
} else {
	$fileList = array();
	$handle = opendir($folder);
	while ( false !== ( $file = readdir($handle) ) ) {
		$file_info = pathinfo($file);
		if (
		    isset( $extList[ strtolower( $file_info['extension'] ) ] )
		) {
			$fileList[] = $file;
		}
	}
	closedir($handle);
 
	if (count($fileList) > 0) {
		$imageNumber = time() % count($fileList);
		$img = $folder.$fileList[$imageNumber];
	}
}
 
if ($img!=null) {
	$imageInfo = pathinfo($img);
	$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
	header ($contentType);
	readfile($img);
} else {
	if ( function_exists('imagecreate') ) {
		header ("Content-type: image/png");
		$im = @imagecreate (100, 100)
		    or die ("Cannot initialize new GD image stream");
		$background_color = imagecolorallocate ($im, 255, 255, 255);
		$text_color = imagecolorallocate ($im, 0,0,0);
		imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
		imagepng ($im);
		imagedestroy($im);
	}
}
 
?>

Open in new window

0
tec2mro
Asked:
tec2mro
  • 2
1 Solution
 
Roger BaklundCommented:
I can't find anything wrong. I tried it on my system, and it worked without modifications. Both images and html pages are displayed correctly.
0
 
Roger BaklundCommented:
Running apache 2.2.9 with PHP 5.2.6 on MS Vista, and tested the script with IE7 and FF3.0.4
0
 
tec2mroAuthor Commented:
I had a feeling it may have something to do with my web server. Thanks for verifying.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now