Created
May 6, 2023 15:08
-
-
Save abdasis/e4c7024e0617d33b825d58eac0f25170 to your computer and use it in GitHub Desktop.
Controller untuk download
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 | |
namespace App\Http\Livewire; | |
use App\Services\TitkokAPI\MaatootzAPI; | |
use Livewire\Component; | |
class Beranda extends Component | |
{ | |
public $url; | |
public $data = []; | |
public function rules() | |
{ | |
return [ | |
'url' => 'required|url' | |
]; | |
} | |
public function download(MaatootzAPI $maatootzAPI) | |
{ | |
$this->validate(); | |
$this->data = $maatootzAPI->getVideo($this->url); | |
} | |
public function downloadFile() | |
{ | |
$nama_file = $this->data['path_video']; | |
return response()->download(public_path('storage/video/' . $nama_file)); | |
} | |
public function downloadWatermark() | |
{ | |
$nama_file = $this->data['path_video_asli']; | |
return response()->download(public_path('storage/video-original/' . $nama_file)); | |
} | |
public function streamDownload($url, $nama_file) | |
{ | |
$konten_video = file_get_contents($url); | |
file_put_contents($nama_file, $konten_video); | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/octet-stream'); | |
header('Content-Disposition: attachment; filename="' . basename($nama_file) . '"'); | |
header('Content-Length: ' . filesize($nama_file)); | |
readfile($nama_file); | |
} | |
public function render() | |
{ | |
return view('livewire.beranda')->layout('layouts.guest'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment