%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/public_html/admin1/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use Intervention\Image\Facades\Image;
class FileController extends Controller
{
public function getFile($type, $path)
{
abort_if(!in_array($type, ['file', 'image']), 404);
$filePath = '';
try {
$decrypted = self::encryptDecrypt($path, 'decrypt');
// The file name from $decrypted.
$fileName = basename($decrypted);
$file_data = file_get_contents(asset_url_local_s3($decrypted), false, stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]));
if ($type == 'file') {
// Stream the file to the browser.
return response()->streamDownload(function () use ($file_data) {
echo $file_data;
}, $fileName);
}
$filePath = Image::make($file_data)->response();
} catch (\Exception $e) {
abort(404);
}
return $filePath;
}
public static function encryptDecrypt($string, $action = 'encrypt')
{
$encryptMethod = 'AES-256-CBC';
$secret_key = 'worksuite'; // User define private key
$secret_iv = 'froiden'; // User define secret key
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16); // sha256 is hash_hmac_algo
if ($action == 'encrypt') {
$output = openssl_encrypt($string, $encryptMethod, $key, 0, $iv);
return base64_encode($output);
}
if ($action == 'decrypt') {
return openssl_decrypt(base64_decode($string), $encryptMethod, $key, 0, $iv);
}
}
}