PHP force download, htaccess deny all, cant read file header
I want to download files from folder that is protected for normal visit by
.htaccess. I found many tutorials but none is working for me.
.htaccess
<files "passportScan.jpg">
deny from all
</files>
php
$file_name = 'passportScan.jpg';
$file_url = self::SERVER_URL . 'uploads/prom_conf/'.$user['uid'].'/' .
$file_name;
header("Content-Description: File Transfer");
header('Content-Type: image/jpeg');
header("Content-disposition: attachment; filename=\"".$file_name."\"");
readfile($file_url);
When I visit url /uploads/passportScan.jpg it is forbidden. That is
correct. But when I call my php method it force download the file but then
there is error "Can't read file header! Uknown file format or file not
found!"
EDIT If I delete the htaccess it works fine.
No comments:
Post a Comment