Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typo3 php file in public folder access controller function

is there any posibillity to access a controller function from a php file that is based in resource/public/php/file.php

What I want is this php file is special file I use it for this:

<img src="file.php"></img> 

I will disable readable paths. So this php file does some encryption and need a connection to a normal controller function.

thanks

like image 200
Felix Avatar asked Aug 23 '26 09:08

Felix


1 Answers

is there any posibillity to access a controller function from a php file that is based in resource/public/php/file.php

Yes, it is possible but therefor you need to bootstrap the TYPO3 core as well. Or if it is a static and public method than you can call it directly.

But this seems not the right way to do it in your case.

Assuming you're working on some kind of captcha thing you should consider your own page type for rendering the dynamic images. Here's a working example:

TypoScript Setup

In TypoScript we're registering our own page typ and pointing it out to our extension, controller and action:

DynamicCaptchaImage = PAGE
DynamicCaptchaImage {

    typeNum = 1234

    10 = USER_INT
    10 {
        userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
        pluginName = Pi1
        extensionName = MyExtName
        vendorName = MyCompanyName
        controller = MyExtbaseController
        action = renderCaptchaImage
        # view =< plugin.tx_myextname.view  // you provide the view yourself
        # persistence =< plugin.tx_myextname.persistence // in case you need a repository you should uncomment it
        settings =< plugin.tx_myextname.settings
    }

    config {
        disableAllHeaderCode = 1
        additionalHeaders = Content-Type: image/png
        xhtml_cleaning = 0
        admPanel = 0
        debug = 0
    }
}

See also: Registering a custom typeNum-based Controller access

Controller

Here's an example how your controller and action should look like:

<?php
namespace MyCompanyName\MyExtName\Controller;

/**
 * MyExtbaseController
 */
class MyExtbaseController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

    /**
     * Render Captcha Image Action
     *
     * @return void
     */
    public function renderCaptchaImageAction() {

        // Send some headers
        header('Content-Type: image/png');

        // < do your magic stuff here >

        // Breaks the script because we've sent already some headers and want
        // to prevent that TYPO3 is adding another stuff (eg. for debugging purposes)
        // that can break the image from loading.
        // return FALSE; does not stop doing that!
        exit;
    }

}

See also: Extbase wiki

Accessing the controller

Now we've configured the custom page type we're allowed to access the controller by calling the page type given in the TypoScript setup.

Eg. http://www.example.com?type=1234 points out to the renderCaptchaImageAction() in the MyExtbaseController.

Fluid

In Fluid you can link to the page type you've configured by:

<img src="{f:link.page(pageType: 1234)}" />

See also: Fluid wiki

Realurl

If you're using the extension realurl you can change ?type=1234 to captcha.png by:

// [...]
'fileName' => array(
    'index' => array(
        'captcha.png' => array(
            'keyValues' => array(
                'type' => 1234,
            ),
        ),
    ),
),
// [...]

See also: Realurl wiki

like image 162
Arek van Schaijk Avatar answered Aug 25 '26 23:08

Arek van Schaijk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!