Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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 力';另存为';svg文件_Php - Fatal编程技术网

Php 力';另存为';svg文件

Php 力';另存为';svg文件,php,Php,我有以下文件: 下载.php <?php $filename = $_GET["filename"]; if ($filename) { $path = "/svg_files/".$filnavn.""; header('Content-Transfer-Encoding: binary'); // For Gecko browsers mainly header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($pa

我有以下文件:

下载.php

<?php 

$filename = $_GET["filename"];

if ($filename) {
$path = "/svg_files/".$filnavn."";
header('Content-Transfer-Encoding: binary');  // For Gecko browsers mainly
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Accept-Ranges: bytes');  // For download resume
header('Content-Length: ' . filesize($path));  // File size
header('Content-Encoding: none');
header('Content-Type: application/svg');  // Change this mime type if the file is not PDF
header('Content-Disposition: attachment; filename=' . $filename);  // Make the browser display the Save As dialog
}
?>

它位于svg_文件文件夹中。但当我跑步时:

myweb.com/svg\u files/download.php?filename=file.svg


我只得到一个空文件。

您必须将文件内容输出到浏览器。。 使用
readfile
file\u获取内容
echo
或类似方法

作为旁注:注意所谓的目录遍历攻击。你可能需要采取一些预防措施。