Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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_File_Download_Include - Fatal编程技术网

包含在内的PHP下载文件

包含在内的PHP下载文件,php,file,download,include,Php,File,Download,Include,我如何使用PHP的include函数来包含一个文件,然后修改标题,使其强制浏览器(至少是这样称呼的)自行下载PHP文件。是否也可以修改预设的保存名称,以便将扩展名从*.php更改为其他名称 提前谢谢 PHP函数将解析该文件。你想做的是使用或 以下是readfile文档中的一个示例: $file = 'somefile.gif'; if (file_exists($file)) { header('Content-Description: File Transfer'); hea

我如何使用PHP的include函数来包含一个文件,然后修改标题,使其强制浏览器(至少是这样称呼的)自行下载PHP文件。是否也可以修改预设的保存名称,以便将扩展名从*.php更改为其他名称

提前谢谢

PHP函数将解析该文件。你想做的是使用或

以下是readfile文档中的一个示例:

$file = 'somefile.gif';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
更改标题以满足您的特殊需要。查看以上链接了解更多信息。

PHP函数将解析该文件。你想做的是使用或

以下是readfile文档中的一个示例:

$file = 'somefile.gif';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}

更改标题以满足您的特殊需要。查看以上链接了解更多信息。

您确切指的是哪个PHP文件?包含文件还是包含文件?包含文件。这就是为什么我要包含一个文件。所以你不知道包含文件的路径,只下载包含文件。你确切的意思是哪个PHP文件?包含文件还是包含文件?包含文件。这就是为什么我要包含一个文件。因此,您不知道包含文件的路径,只下载包含文件。OK。谢谢你的邀请!但是我怎么才能下载文件呢?甚至强制下载?使用:echo file_get_contents'source_of_file';如何将文件内容与子文件夹一起使用?它就是不起作用:尝试使用绝对路径。为了获得更大的灵活性,您可以使用$\u SERVER['DOCUMENT\u ROOT']预先设置一个相对路径。好的。谢谢你的邀请!但是我怎么才能下载文件呢?甚至强制下载?使用:echo file_get_contents'source_of_file';如何将文件内容与子文件夹一起使用?它就是不起作用:尝试使用绝对路径。为了获得更大的灵活性,您可以使用$\u SERVER['DOCUMENT\u ROOT']预先设置相对路径。