Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php下载函数给了我一个空文件_Php - Fatal编程技术网

php下载函数给了我一个空文件

php下载函数给了我一个空文件,php,Php,这是我的密码 <?php $file = $_GET['file']; if (file_exists("uploaded_files\\" .$file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . filesize($file)); heade

这是我的密码

<?php

$file = $_GET['file'];

if (file_exists("uploaded_files\\" .$file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Length: ' . filesize($file));
    header("Content-Disposition: attachment; filename=" . basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile("uploaded_files\\" .$file);
    exit;
} else {
    echo "Download failed";
}
?>

您需要更改文件位置,因为
readfile()
需要文件的绝对路径

<?php
$file = $_GET['file']
$file = "uploaded_files/".$file;

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}else {
  echo "Download failed";
}
?>

您需要更改文件位置,因为
readfile()
需要文件的绝对路径

<?php
$file = $_GET['file']
$file = "uploaded_files/".$file;

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}else {
  echo "Download failed";
}
?>

有没有办法让我的下载功能按预期工作?上传文件目录的权限是什么?他们都有读写权限更新你的问题有没有办法让我的下载功能按预期工作?上传文件目录的权限是什么?他们都有读写权限更新您的问题plsreadfile(“C:\\xampp\\htdocs\\fyproject\\uploaded\u files\\”$file);还是不行谢谢!“我真蠢!”卡尔文,我们在这里都有点蠢,兄弟P最佳Luckreadfile(“C:\\xampp\\htdocs\\fyproject\\uploaded\u files\\”$file);还是不行谢谢!“我真蠢!”卡尔文,我们在这里都有点蠢,兄弟祝你好运