Menu Close

Modify AjaXplorer for show images in browser

If you want that AjaXplorer shows in browser images from generated public links, you can modify  class.fsAccessDriver.php (in Ajaxplorer4.3.3 is under plugins\access.fs\) at about Line 202:

 

AJXP_Controller::applyHook("dl.localname", array($this->urlBase.$selection->getUniqueFile(), &$localName, $this->wrapperClassName));
// $this->readFile($this->urlBase.$selection->getUniqueFile(), "force-download", $localName);
$Nomefile = $selection->getUniqueFile();
AJXP_Logger::debug("trovo l'estensione di ".$Nomefile);
$pathParts = pathinfo($Nomefile);
//if(isset($pathParts['extension']))
if (array_key_exists('extension', $pathParts))
{
    $ext = strtoupper($pathParts['extension']);

    AJXP_Logger::debug("estensione: ".$ext);

    $pos = strpos($_SERVER["REQUEST_URI"] , "public");

    if ($pos !== false) {
        if ( $ext == 'JPG' || $ext == 'BMP' || $ext == 'PNG' || $ext == 'JPEG')
        {
            $this->readFile($this->urlBase.$selection->getUniqueFile(), "image", $localName);
        }
        else
        {
            $this->readFile($this->urlBase.$selection->getUniqueFile(), "force-download", $localName);
        }
    }
 else
    {
        $this->readFile($this->urlBase.$selection->getUniqueFile(), "force-download", $localName);
    }
} else { $this->readFile($this->urlBase.$selection->getUniqueFile(), "force-download", $localName); }

With a bit of code I check if the current request it’s done from a public url, and in this case I force the visualization of the image instead of simple download it.
I have to check Request_URI for “public” because otherwise when you press the “download” button inside ajaxplorer the browser opens the image instead of download it.

 

If you need to enable debug mode, you can modify conf/bootstrap_context.php with:

define("AJXP_SERVER_DEBUG"  , true);
Posted in Domotica e Cloud, News, Web Development

Leave a Reply

Your email address will not be published. Required fields are marked *