Zum Inhalt springen

Bilder außerhalb WebRoot laden

Erstellt am 9. November 2006 · Noch keine Antworten

Tags: Bilder, Tipp

konkret ·

Nur zur Info, für jene die sich fragen, wie man bilder von außerhalb des Web-Roots in Typo3 einbinden kann. da das ja mit der cObj->IMAGE Funktion von Typo3 nicht geht (Habe selber länger gebraucht habe bis ich es verstanden habe).
z.Bsp.:
Web-Root: /home/xyz/htdocs/
Bilder: /home/xys/bilder/

Zuerst in der class.tx_ExtensionKey_pi1.php folgendes einfügen:

<?php
function show_image() {
		#get the parts out of the template
		$template["total"] = $this->cObj->getSubpart($this->templateCode,'###PICTURES###');

		$imageId = 'Bild001';
			
		$markerArray['###IMAGE###'] = '<img src="'.t3lib_extMgm::siteRelPath('ExTensionKey').'pi1/image.php?imageId='.$imageId.'" alt="" />';

		$data = $this->cObj->substituteMarkerArrayCached($template["total"], $markerArray, array(), array());
		return $data;
	}

function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->pi_USER_INT_obj=1;

        # Get the template
        $this->templateCode = $this->cObj->fileResource($conf["templateFile"]);
        if ($this->templateCode=="") {
            return '<h3>'.$this->pi_getLL('no_template').'</h3>'.$this->conf['templateFile'];
        }

		$content = $this->show_image();
	
		return $this->pi_wrapInBaseClass($content);
	}
?>

und im pi1/ Ordner der Extension dann noch die Datei image.php erstellen:

<?php
	$imageId = $_GET['imageId'];	
	$file = '/home/xyz/bilder/'.$imageId.'.jpg';	

	header("Content-type: image/jpeg");	
	$image = imageCreateFromJPEG($file);
	$image_show = imageJPEG($image);
?>

Durch den externen Aufruf der image.php umgeht man die header() Problematik.
Hier mal nur für ein Bild im jpeg Format gezeigt. Kann natürlich noch Schleifen und Daten aus einer Datenbankabfrage erweitert werden.

mfg konkret