Akhirnya update lagi nih.. kali ini saya akan memberikan tips CakePHP untuk membuat script code untuk force download..
berikut contoh skrip download untuk CakePHP:
<?php
function download($id = null){
$file = $this->Download->findById($id);
$direktori = "files/downloads/";
$filename = $file['Download']['namafile'];
$extension = strtolower(substr(strrchr($filename,"."),1));
switch($extension){
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "rar": $ctype="application/rar"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/proses";
}
header("Content-Type: octet/stream");
header("Pragma: private");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename="".basename($filename)."";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($direktori.$filename));
readfile("$direktori$filename");
exit();
function download($id = null){
$file = $this->Download->findById($id);
$direktori = "files/downloads/";
$filename = $file['Download']['namafile'];
$extension = strtolower(substr(strrchr($filename,"."),1));
switch($extension){
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "rar": $ctype="application/rar"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/proses";
}
header("Content-Type: octet/stream");
header("Pragma: private");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename="".basename($filename)."";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($direktori.$filename));
readfile("$direktori$filename");
exit();
}
?>
Semoga bermanfaat..
hadif
mas, sharing donk tentang cara bikin thumbnail / resize di CakePHP.. klo perlu sediain file donlod nya gratis.. :-)
Agus Saputra
Hadif @ sy sudah menyiapkan pembahasan resize gambar pada CakePHP untuk buku edisi 2. . doakan saja y supaya bs d terbitkan. . =)
yanto lg nunggu
Mas, kapan ni keluar bukunya? uda ga sabar ni..
Agus Saputra
Perkiraan pertengahan februari mas. . :)
Simon
Mas, minta matengan dari script di atas dong. Trus cara uploadnya apa hampir sama dengan upload gambar??
Agus Saputra
Simon @ maksudnya source code lengkapnya ya?.. nanti akan saya usahakan upload :-)
Untuk uploadnya hampir sama kok.. :-)
surya
mas... kalo buat pooling di cakephp gmana tuh??
Slamet Wiryawan
Bro, bagaimana penerapannya kalau di Versi 2. Saya sudah baca Trik Dasyat ********* !!!. Untuk Upload saya pake plugin, namun bagaimana function download() di Controller apa sama atau beda ?