We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25388
    • 31 Posts
    I wrote a little gallery snippet which seems to work fine for me in FireFox but if i try to access the site in IE with caching turned off (which is absolutely nescessary) i get a server error site. It does not look like a server error and has no HTTP error code...

    Any ideas what this could be?

    /**
     * Gallery Snippet
     * ________________________________________
     * 
     *
     * @author Roland Schär
     * @date   2006-02-19
     */
    
    $basefolder = '/assets/gallery/';
    $maxwidth = isset($maxsize) ? $maxsize :  120;
    $imgRoot = $_SERVER['DOCUMENT_ROOT'] . $basefolder;
    
    
    
    if( isset($_GET['image']) && isset($_GET ['gallery']) ) {
    	$images = getImages($imgRoot . $_GET['gallery']);
    	$pos = array_search($_GET['image'],$images);
    
    	$overview .= '<p><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'"><< zurück zur Galerie</a></p><div>';
    	if($pos>0)
    			$overview .= '<p style="float:left;width:50%;text-align:left;"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'&image='.$images[$pos-1].'">vorheriges Bild</a></p>';
    	if($pos<count($images)-1) 
    			$overview .= '<p style="float:right; width:50%;text-align:right;"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'&image='.$images[$pos+1].'">nächstes Bild</a></p>';
    	$overview .= '</div>';
    	$overview .= '<div class="galleryImageLarge"><img src="assets/gallery/thumb.php?pic=' . $_GET['gallery'] . '/' . $_GET['image']  . '&width=450" alt="" /></div>';
    
    }else if(isset($_GET['gallery'])){
    	
    	$overview = '<p><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'"><< zurück zur Übersicht</a></p>';
    	$images = getImages($imgRoot . $_GET['gallery']);
    	for($i=0; $i<count($images); $i++){
    		$overview .= '<div class="galleryImg"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'&image='.$images[$i].'"><img src="assets/gallery/thumb.php?pic=' . $_GET['gallery'] . '/' . $images[$i]  . '&width='.$maxwidth.'" border="0" alt="" /></a></div>';
    	}
    
    }else{
    
    	$galleries = getGalleries($imgRoot);
    	for($i=0; $i<count($galleries); $i++){
    		$previewImage = getPreviewImage($imgRoot . $galleries[$i]);
    		if($previewImage != '') {
    			$img = '<img src="assets/gallery/thumb.php?pic=' . $galleries[$i] . '/' . $previewImage . '&width=120" alt=""  border="0" />';
    		}else{
    			$img = '';
    		}
    		$overview .= '<div class="gallery"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$galleries[$i].'">' . $img . $galleries[$i].'</a></div>';
    	}
    
    }
    
    return $overview;
    
    /** **/
    function getGalleries($fld){
    	$arrTopics = array();
    	$i = 0;
    	$dir = opendir($fld);
    	while( $file = readdir($dir) ){
    		if( $file != "." && $file != ".." ){
    			if( is_dir($fld."/".$file) ){
    				$arrTopics[$i] = $file;
    				$i++;
    			}
    		}
    	}
    	return $arrTopics;
    }
    
    function getImages($fld){
    	if( file_exists($fld) ){
    		$imgPath = opendir( $fld );
    		$i = 0;
    		while($imgFile = readdir($imgPath)){
    			if( is_file($fld."/".$imgFile) ){
    				$arrFiles[$i] = $imgFile;
    				$i++;
    			}
    		}
    	}
    	return $arrFiles;
    }
    
    function getPreviewImage($fld){
    	$arrFiles = array();
    	if( file_exists($fld) ){
    		$imgPath = opendir( $fld );
    		$i = 0;
    		while($imgFile = readdir($imgPath)){
    			if( is_file($fld."/".$imgFile) ){
    				$arrFiles[$i] = $imgFile;
    				$i++;
    			}
    		}
    	}
    	if( !in_array('titelbild.jpg',$arrFiles) ){	
    		return $arrFiles[0];
    	}elseif( count($arrFiles) == 0 ){
    		return '';
    	}
    	return 'titelbild.jpg';
    }
    
    
    
      • 25388
      • 31 Posts
      Weird is that the site works if i’m logged into backend...

      I think the problem is in my external script which should return thumbnails. Depending on the Firefox version i use it returns me the file index.php for saving. The script itself seems to work fine but if i include it in the img tag it wont >:(
      This is driving me crazy, spent already hours looking for a solution!

      <?php
      header('Last-Modified: '.gmdate('D, d M Y H:i:s', $timestamp).' GMT'); 
      header("Content-type: image/jpeg");
      header('Content-transfer-encoding: binary');
      
      $im=imagecreatefromjpeg($pic);
      $orange=imagecolorallocate($im, 220, 210, 60);
      $px=(imagesx($im) - 7.5 * strlen($string)) / 2;
      $old_x=imageSX($im);
      $old_y=imageSY($im);
      $new_w=(int)($width);
      
      if (($new_w<=0) or ($new_w>$old_x)) {
       $new_w=$old_x;
      }
      $new_h=($old_x*($new_w/$old_x));
      
      if ($old_x > $old_y) {
         $thumb_w=$new_w;
         $thumb_h=$old_y*($new_h/$old_x);
      
      }
      if ($old_x < $old_y) {
         $thumb_w=$old_x*($new_w/$old_y);
         $thumb_h=$new_h;
      }
      if ($old_x == $old_y) {
         $thumb_w=$new_w;
         $thumb_h=$new_h;
      }
      
      $thumb=ImageCreateTrueColor($thumb_w,$thumb_h);
      imagecopyresized($thumb,$im,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
      imagejpeg($thumb,"",90);
      imagedestroy($thumb);
      ?>