File: D:/HostingSpaces/SBogers10/immoginis.komma.pro/app/controllers/DownloadController.php
<?php
class DownloadController extends BaseController
{
public function download($fileName = 'document')
{
//If file is not present in the request return 404
if (!\Request::has('location')) return \App::abort('404');
//Decoded the file name
$file = base64_decode(\Request::get('location'));
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//If the code is not 200 abort
if ($code != 200) return \App::abort('404');
curl_close($ch);
//Empty file, abort
if (strlen($data) == 0) return \App::abort('404');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
//Set the filename
header('Content-Disposition: attachment; filename=' . basename($fileName));
ob_clean();
flush();
readfile($file);
exit;
}
}