Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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缓冲区输出。我对将输出内容写入服务器上的文件,然后允许下载不感兴趣。我通过在浏览器上打印来检查变量输出。由于缓冲区应该作为文件在客户端下载,我应该在哪里指定文件名 <?php $file=$_POST['file']; header('Content-Description: File Transfer'); header('Content-Type: application/x-java-jnlp-file'); ob_clean(); f

我试图在客户端下载PHP缓冲区输出。我对将输出内容写入服务器上的文件,然后允许下载不感兴趣。我通过在浏览器上打印来检查变量输出。由于缓冲区应该作为文件在客户端下载,我应该在哪里指定文件名

<?php
  $file=$_POST['file'];
  header('Content-Description: File Transfer');
  header('Content-Type: application/x-java-jnlp-file');  
  ob_clean();
  flush();
  readfile($file);
 ?>

~

简单地使用这个方法

<?php
$file = 'monkey.gif';

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));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>

需要更多帮助

您需要“内容处置”标题:


完整示例:

RTFM:您可能只需要
echo$file
。您还需要了解
$\u文件
superglobal和使用此方法
header( 'Content-Disposition: attachment; filename="downloaded.pdf"' );