I just wanted to make some kind of "download service" but it isn't working.
Whole download.php:
<?php
include "utils/config.php";
include "utils/utils.php";
if($isLoggedIn && isset($_POST['id']) && hasProduct($userid,$_POST['id'])){
$ID = $_POST['id'];
$pdata = getProduct($ID);
$file = $pdata['file'];
$name = $pdata['dlfile'];
$mime = $pdata['file_mime_type'];
#echo $file."<br>".$name."<br>".$mime;
/**
* $file = "assets/files/151708025047541"
* $name = "API.jar"
* $mime = "application/java-archive"
*/
download($file,$name,$mime); // <-- wouldn't work
#download("assets/files/151708025047541","API.jar","application/java-archive"); // <-- wouldn't work
}
#download("assets/files/151708025047541","API.jar","application/java-archive"); // <-- would work fine
?>
Function "download" in utils.php:
function download($f_location, $f_name, $type){
header('Content-Description: File Transfer');
header('Content-Type: '.$type);
header('Content-Length: ' . filesize($f_location));
header('Content-Disposition: attachment; filename="' . basename($f_name).'"');
ob_clean();
readfile($f_location);
}
The only thing "config.php" contains are some variables. The only thing "utils.php" contains are some functions and it's connecting to the database (which is needed for $isLoggedIn, hasProduct (...) and getProduct (...).
The download itself is wokring, but it wants to download a file with zero content and with the name "download.php". At my comments you see, if I try the same function (with static args) outside the if-block the download works fine. But if I try to use function (with static args) inside the if-block it will give me the same problem.
Funny thing is that the same function still worked a few months ago.
Am I doing something wrong? How can I download these files dynamic with an authorization-check (as I have already tried)?
I hope you understand my problem:)
A Download-Manager add-on was trying to catch the download..
Just added an exception/disabled the add-on and now it's working!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.