-
-
Save Sentences/3938976 to your computer and use it in GitHub Desktop.
Extended File for Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* File | |
* | |
* Note: Remember to remove the "File" alias in APP_DIR/config/application.php | |
* | |
* @author Phill Sparks <me@phills.me.uk> | |
*/ | |
class File extends Laravel\File { | |
/** | |
* Create a response that will force a file to be downloaded. | |
* | |
* @param string $path | |
* @param string $name | |
* @return Response | |
*/ | |
public static function inline($path, $name = null) | |
{ | |
if (is_null($name)) | |
{ | |
$name = basename($path); | |
} | |
$response = Response::make(static::get($path)); | |
$response->header('Content-Type', static::mime(static::extension($path))); | |
$response->header('Content-Disposition', 'inline; filename="'.$name.'"'); | |
$response->header('Content-Transfer-Encoding', 'binary'); | |
$response->header('Expires', 0); | |
$response->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); | |
$response->header('Pragma', 'public'); | |
$response->header('Content-Length', filesize($path)); | |
return $response; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'GET /files/(:any)' => array('name' => 'file', 'do' => function($name) { | |
$path = STORAGE_PATH.'files/'.$name; | |
if (file_exists($path)) | |
{ | |
return File::inline($path); | |
} | |
return Response::error(404); | |
}), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment