index.php:

// STUFF
		// STEP 1: imagecreatetruecolor ONLY IF GD 2.0+ SUPPORTED AND FOUND
		if ($this->isSuccessful && !$hasMogrified && $image && !$newImage && function_exists('imagecreatetruecolor') && preg_match('/2\.0/i', $this->gd_info_array[0])) {
		 $newImage = @imagecreatetruecolor($configArray['width'], $configArray['height']);
		 if (!$newImage) {
		  $this->isSuccessful = false;
		  $this->setErrorArray(array('action' => 'Could not seem to create new image'));
		 }
	 	}

This block of code will sometimes, for reasons I just don't understand, cause a forced-download of the entire index.php script! This is not even a consistent issue inasmuch as this only happens to certain JPEG images. I am completely unable to discern a pattern; it happens to some JPEG images and not to others; furthermore, this behavior does not occur in GIF or PNG images.

I am using PHP 4.3.9 with GD 2.0.1 in Linux RHEL 4.

Thanx
Phil

    Ok I apoligize I was wrong; after some more testing and debugging, the error actually occurs here:

    $imageStatArray = @getimagesize(actual_path(realpath($this->locationPath . '/' . $this->fileName)));
    list($origWidth, $origHeight, $type) = $imageStatArray;		// GET ATTRIBUTES
    eval('$image = ' . $functionArray[$type] . '(actual_path("$this->locationPath/$this->fileName"));'); // IT DIES HERE
    // THIS IS WHERE $functionArray IS AN ARRAY OF NUMERICAL TYPES MATCHED TO PHP FUNCTIONS
    

    The purpose is to create an all-inclusive PHP object image resource link that can be for a JPEG, a GIF, a PNG or whatever else is available.

    Thanx
    Phil

      When I use image processing, I always force JPEG's to the jpg extension because it can be either jpg or jpeg... maybe thats where your code is breaking down.

        No that's not it, all of my images have .jpg extension. All of them also come from the same source and all have the exact same permissions, ownership and group designation.

        Phil

          Well, first off, you might try taking the object references out of the string and concatenate them, like so:

          eval('$image = ' . $functionArray[$type] . '(actual_path($this->locationPath . "/" . $this->fileName));');

          Also, perhaps a forced Content-Disposition would stop browsers from popping up a download box?

          header('Content-Disposition: inline');

          EDIT: Also, have you turned on display_errors and set error_reporting to E_ALL ? If you accept the "download" does the file contain any errors, or is it just the image data?

            I also think that eval() is unnecessary in this situation (but then it usually is, so that's no surprise 🙂). PHP already provides functions to allow calling functions named in variables..

            $image = call_user_func($functionArray[$type], actual_path($this->locationPath.'/'.$this->fileName);

            In fact, if these function names are strings (as opposed to object methods), then

            $image = $functionArray[$type](actual_path($this->locationPath.'/'.$this->fileName);
              Write a Reply...