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

Posted on 2008-11-18
Last Modified: 2013-12-13
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.

	$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;




	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);


} 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);





Open in new window

Question by:tec2mro
    LVL 39

    Accepted Solution

    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.
    LVL 39

    Expert Comment

    by:Roger Baklund
    Running apache 2.2.9 with PHP 5.2.6 on MS Vista, and tested the script with IE7 and FF3.0.4

    Author Comment

    I had a feeling it may have something to do with my web server. Thanks for verifying.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now