simotod/slim-download

Slim extension to implement download view render

v1.1.0 2015-03-22 15:25 UTC

This package is auto-updated.

Last update: 2024-04-16 06:19:11 UTC


README

This is an extension to the SLIM framework vers.2 to implement the download of a file from a route. It can be used to check the user permissions before of permits the downloading of a file, to count the number of download or for something else useful.

##Installation Using composer you can add use this as your composer.json

    {
        "require": {
            "simotod/slim-download": "dev-master"
        }
    }

##Usage

    require 'vendor/autoload.php';

    $app = new \Slim\Slim(); 

	$app->get('/download', function () use ($app) {
		//Do some stuff here
		
		$filepath = "/path/to/file";
		
		$app->view(new \SimoTod\SlimDownload\DownloadView());
		$app->render($filepath);
	});
	
	$app->run();
	

###example method all your requests will be returning a file output. the usage will be $app->render( (string)$FILE_PATH, (array)$DATA); Downladed file use the real name and 'application/octet-stream' as content type. Content type can be overriden by $DATA["CONTENT_TYPE"]. File name can be overriden by $DATA["FILENAME"].

	$app->get('/download', function () use ($app) {
		//Do some stuff here
		
		$filepath = "/path/to/pdf";
		$data = array();
		$data["CONTENT_TYPE"] = "application/pdf";
		$data["FILENAME"] = "sample.pdf";
		
		$app->view(new \SimoTod\SlimDownload\DownloadView());
		$app->render($filepath);
	});