Commit acc65b55 by Aan Choesni Herlingga

front download file

parent ba184106
<?php
namespace App\Http\Controllers\Webprofile\Front;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories;
use App\Models\Webprofile\CategoriesFile;
use App\Models\Webprofile\Design;
use App\Models\Webprofile\File;
use App\Models\Webprofile\Menu;
use App\Models\Webprofile\Posts;
use App\Repositories\Webprofile\FileRepository;
class DownloadController extends Controller
{
public function index()
{
$categoriesFile = CategoriesFile::where('is_active', 1)->orderBy('created_at', 'DESC')->with(['rFile'])->get();
$setting = webprofilesetting();
$menu = Menu::orderby('urutan', 'asc')->get();
$hot = Posts::where('post_status', '1')->orderby('viewer', 'desc')->limit('5')->get();
$categories = Categories::where('is_active', '1')->get();
$widget_right = Design::where('name_design', 'widget_right')->orderBy('urutan', 'ASC')->get();
$widget_left = Design::where('name_design', 'widget_left')->orderBy('urutan', 'ASC')->get();
$data = [
'categoriesFile' => $categoriesFile,
'setting' => $setting,
'menu' => $menu,
'hot' => $hot,
'categories' => $categories,
'widget_right' => $widget_right,
'widget_left' => $widget_left,
];
return view('webprofile.front.' . $setting['theme'] . '.download', $data);
}
public function downloadFile($id)
{
$setting = webprofilesetting();
$fileModel = new File;
$fileRepo = new FileRepository($fileModel);
$dbfile = $fileRepo->findId($id);
if ($setting['external_storage'] == 1) {
$file = $setting['url_static'] . '/' . $setting['directory'] . '/file/' . $dbfile->file;
} else {
$file = url('/storage/file/' . $dbfile->file);
}
// dd($file);
$fileRepo->countDownload($dbfile);
// if ($fileRepo->is_url_exist($file)) {
$filename = $dbfile->slug;
$tempImage = tempnam(sys_get_temp_dir(), $filename);
stream_context_set_default([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
copy($file, $tempImage);
return response()->download($tempImage, $filename);
// } else {
// Alert::error('File tidak ditemukan');
// return redirect()->back();
// }
}
}
......@@ -76,4 +76,23 @@ class FileRepository extends StorageRepository
->rawColumns(['action', 'status', 'category', 'file', 'downloaded'])
->make(true);
}
public function is_url_exist($url)
{
stream_context_set_default([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$headers = get_headers($url);
return stripos($headers[0], "200 OK") ? true : false;
}
public function countDownload(File $file)
{
$file->downloaded = $file->downloaded + 1;
return $file->save();
}
}
@extends('webprofile.front.jollyany.master')
@section('content')
<section class="post-wrapper-top jt-shadow clearfix">
<div class="container">
<div class="col-lg-12">
<h2>Download</h2>
</div>
</div>
</section><!-- end post-wrapper-top -->
<section class="blog-wrapper">
<div class="container">
<div class="row">
<div id="main-content" class="col-md-12" role="main" align="justify">
<table class="table table-bordered">
<thead>
<tr>
<th style="width: 5%;">No</th>
<th>Nama Dokumen</th>
<th style="width: 15%;">Tanggal Publikasi</th>
<th style="width: 10%;">Option</th>
</tr>
</thead>
<tbody>
@foreach ($categoriesFile as $value)
<tr>
<td colspan="4" style="font-weight: bold;">KATEGORI : {{ $value->name }}</td>
</tr>
@php
$no = 1;
@endphp
@foreach ($value->rFile as $item)
<tr>
<td style="text-align: center; color: black;">{{ $no++ }}</td>
<td style="color: black;">{{ $item->title }}</td>
<td style="text-align: center; color: black;">{{ InseoHelper::tgl($item->created_at) }}</td>
<td style="text-align: center;">
<a href="{{ url('downloadlink/'.$item->id) }}" class="btn btn-info"><i class="fa fa-download"> Download</i></a>
</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
</div>
</div>
</div><!-- end title -->
</div><!-- end container -->
</section><!--end white-wrapper -->
@endsection
......@@ -8,6 +8,6 @@ Route::group(['namespace' => 'Webprofile\Front'], function () {
Route::get('information/{id}', 'InformationController@index')->name('infomation');
Route::get('agenda', 'AgendaController@index')->name('agenda');
Route::get('error', 'ErrorController@index')->name('error');
Route::get('download', 'FrontController@download')->name('download');
Route::get('downloadlink/{data}', 'FrontController@downloadFile')->name('downloadFile');
Route::get('download', 'DownloadController@index')->name('download');
Route::get('downloadlink/{data}', 'DownloadController@downloadFile')->name('downloadFile');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment