[TYPO3-english] Execute php script file including html headers

Script Grandpa k.kirsa at kirsa.de
Wed Apr 6 10:44:46 CEST 2016

While trying to migrate to Typo3 (7.6.4) I'm struggling to get the following to work:

I have a custom php script. It performs some complex tasks within, but eventually just puts out an image file. So a simplified version of it looks like this:

  // eval parameter
  if (isset($_GET['imgsize'])) {
    $img_width = $_GET['imgsize'];
    $img_height = $_GET['imgsize'];
  } else {
    $img_width = 100;
    $img_height = 100;
  // generate pic
  $id = ImageCreate($img_width,$img_height);
  $green = ImageColorAllocate($id, 0, 255, 0);
  ImageFill($id, 0,0,$green);
  // output pic
  Header("Content-Type: image/png");
  // clean up

The content type may vary depending on the image format (gif, jpeg, etc.). And other services rely on that functionality, therefore simply creating a page with the image shown on it does not help.  

Now I want Typo3 to execute that script when a specific url is called.

  or www.somedomain.com/getpic?imgsize=250

Thought it got be quite simple, because Typo3 has to do very little: Just call the script, if a specific url within the Typo3 page tree is requested.
Didn't find much on this topic during my research. Within the page template I can reference to an external script file:

  includeLibs.phpfile = fileadmin/picfunctions/getpic.php

And I can tell Typo3 to suppress generating its own html header:

  config {
    disableAllHeaderCode = 1

Then I am left with USER_INT to call a function in getpic.php. I played with the php script (re-wrote to only one function, then to one class with one function) - but the browser isn't showing any content a all.

  page = PAGE
  page.10 = USER_INT
  page.10 {
    userFunc = picfunctions->getpic

I think it's because these function calls only manipulate the html content generated by Typo3 ($content). But in my case there is no html content - it's a dynamically generated image, based on some url parameters.
Read about PHP_SCRIPT and PHP_SCRIPT_EXT, but they seem to be depricated.
Also tried

  config {
    disableAllHeaderCode = 1
    additionalHeaders = Content-Type:image/png

That just generates an error saying the picture file is bogus. Well, at least it sends the correct html header to the browser.

Any ideas on how to get Typo3 to execute my script for the whole page (including html-headers)?

More information about the TYPO3-english mailing list