[英]PHP download doesn't work properly
I just wanted to make some kind of "download service" but it isn't working. 我只是想提供某种“下载服务”,但是它不起作用。
Whole download.php: 整个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: 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. 唯一的“ config.php”包含一些变量。 The only thing "utils.php" contains are some functions and it's connecting to the database (which is needed for $isLoggedIn, hasProduct (...) and getProduct (...).
“ utils.php”唯一包含的是一些函数,它正在连接数据库($ isLoggedIn,hasProduct(...)和getProduct(...)所需。
The download itself is wokring, but it wants to download a file with zero content and with the name "download.php". 下载本身很麻烦,但它希望下载内容为零且名称为“ download.php”的文件。 At my comments you see, if I try the same function (with static args) outside the if-block the download works fine.
在我的评论中,您看到,如果我在if块之外尝试相同的功能(带有静态args),则下载工作正常。 But if I try to use function (with static args) inside the if-block it will give me the same problem.
但是,如果我尝试在if块中使用函数(带有静态args),它将给我同样的问题。
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.. 一个Download-Manager加载项正在尝试捕获下载。
Just added an exception/disabled the add-on and now it's working! 刚刚添加了一个例外/禁用了插件,现在它可以工作了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.