Search

I have noticed that this event doesn't work with S2?

 <?php

if(!defined("__IN_SYMPHONY__")) die("<h2>Error</h2><p>You cannot directly access this  file</p>");

Class eventDownload_Image Extends Event{

    function __construct($args = array()){
        parent::__construct($args);
    }

    function about(){       
        return array(
                     "name" => "Download Image",
                     "description" => "Place this on any page and add ?dl-image=XXX to the URL. XXX is an image file path, relative to the workspace folder.",
                     "author" => array("name" => "Nick Toye",
                                       "website" => "http://www.nicktoye.co.uk",
                                       "email" => "info@nicktoye.co.uk"),
                     "version" => "1.0",
                     "release-date" => "2007-04-19",
                     "trigger-condition" => "?dl-image=XXX",                         
                     "recognised-fields" => NULL);                       
    }

    function load(){

        if(isset($_GET['dl-image'])) return $this->trigger($_GET['dl-image']);

        return; 

    }

    function trigger($path){

        $image = WORKSPACE . '/' . trim($path, '/');

        if(!is_file($image)) die("<h1>Symphony Fatal Error</h1><p>The requested Image '<strong>$image</strong>' could not be read.<hr /><em>".$_SERVER['SERVER_SIGNATURE']."</em>");

        include(TOOLKIT . "/class.image.php");

        /*
            if(!$info = Image::getMeta($image))
            die("<h1>Symphony Fatal Error</h1><p>The requested Image '<strong>$image</strong>' could not be read.<hr /><em>".$_SERVER['SERVER_SIGNATURE']."</em>");
        */

        // Start sending headers 
        header("Pragma: public"); // required 
        header("Expires: 0"); 
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
        header("Cache-Control: private", false); // required for certain browsers 
        header("Content-Transfer-Encoding: binary"); 

        switch($info['type']) {

            ## GIF
            case IMG_GIF:
                header("Content-type: image/gif");
                break;

            ## JPEG 
            case IMG_JPEG:
                header("Content-type: image/jpeg");
                break;

            ## PNG  
            case IMG_PNG:
                header("Content-type: image/png");
                break;

            ## PDF  
            case PDF:
                header("Content-type: application/pdf");
                break;

            ## Other    
            case IMG_XPM:
                header("Content-type: application/x-shockwave-flash");
                break;

            ## Windows BMP  
            case IMG_WBMP:
                header("Content-type: image/bmp");
                break;              
        }

        header("Content-Length: " . filesize($image)); 
        header('Content-Disposition: attachment; filename="' . basename($image) . '";' );           
        print file_get_contents($image);
        die();

    }
}

 ?>

Is there much that needs to change? Or does anyone have any working method to hand?

Cheers

Doesn't work how? Is it throwing errors, or the download never happens?

Oh sorry,

Well when I put this event in my events folder in S2,

I get this when I go to Components in Symphony.

Fatal error: Cannot make static method Event::about() non static in class eventDownloadImage in /nfs/c02/h03/mnt/29224/domains/test.nicktoye.co.uk/html/wishdesigns/workspace/events/event.downloadimage.php on line 91

Any help on this?

Try changing

function about(){

to

public static function about(){

Should help.

Its giving me this error now:

 Fatal error: Class eventDownload_Image contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Event::__trigger) in /nfs/c02/h03/mnt/29224/domains/test.nicktoye.co.uk/html/wishdesigns/workspace/events/event.download_image.php on line 91

Anyone else able to help here? I know Alistair is busy, so if anyone else has any experience with php events and can help.

Try changing:

if(isset($_GET['dl-image'])) return $this->trigger($_GET['dl-image']);

to

if(isset($_GET['dl-image'])) return $this->__trigger($_GET['dl-image']);

and

function trigger($path){

to

function __trigger($path){

Should help

Ok, progress

 Fatal error: Cannot make static method Event::about() non static in class eventDownload_Image in /nfs/c02/h03/mnt/29224/domains/test.nicktoye.co.uk/html/wishdesigns/workspace/events/event.download_image.php on line 91

Well a different error. I think I really need to spend a couple of weeks and learn some php.

This error is actually happening when I navigate to Components section in Symphony.

Isn't that the same error you had previously?

Oh yeah, I was editing an old version. Well I have just edited the newer version, and I am getting a different error:

 Fatal error: Declaration of eventDownload_Image::__trigger() must be compatible with that of Event::__trigger() in /nfs/c02/h03/mnt/29224/domains/test.nicktoye.co.uk/html/wishdesigns/workspace/events/event.download_image.php on line 91

Try this one out. Has improved code and seems to work fine on my local server.

Right, does it work with PDF downloads?

I guess I should have called it "Download Anything." Try this DS out. I've tweaked it slightly.

Thanks Alistair, this is great. Be excellent if this event was stored in a library for others to use. For me, its things like this that really make me want to stay loyal to this great product.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details