1

需要生成一个txt文件,输出html代码如下

<?php
function video() {
  $video = 'BYN-DEM7Mzw';
  echo '<script type="text/javascript">
    function youtubeFeedCallback( data ){
      document.writeln( data.entry[ "media$group" ][ "media$description" ].$t.replace( /\n/g, "<br/>" ) + "<br/>" ); }
    </script>
    <script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos/'.$video.'?v=2&amp;alt=json-in-script&amp;callback=youtubeFeedCallback"></script>';
}
ob_start();
video();
$output = ob_get_clean();
$desc = $output;
$video = 'BYN-DEM7Mzw';
$arq = $video.".txt";
$f = fopen($arq, "w+");
fclose;
$f = fopen($arq, "a+");
$content = "";
if(filesize($arq) > 0)
$content = fread($f, filesize($arq));
fwrite($f, $desc);
fclose($f);
?>

文件保存我的脚本而不是输出 html 的问题

4

1 回答 1

0

我认为您应该在其中使用正确的标题和正确的mime

例如

header('Content-Description: File Transfer');
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename='.$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));

if ($file != '')
{ 
    echo file_get_contents($file);
}
于 2012-07-20T13:41:27.910 回答