Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.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完成响应生成后修改HTTP响应内容_Php_Linux_Apache_Ubuntu - Fatal编程技术网

在PHP完成响应生成后修改HTTP响应内容

在PHP完成响应生成后修改HTTP响应内容,php,linux,apache,ubuntu,Php,Linux,Apache,Ubuntu,我有一个关于修改xmlhttprequest的responseText的问题 index.html将xmlhttprequest(req)发送到b.php,(index.html和b.php都放在Tests文件夹中) b.phpechos二进制(video/mp4)数据 我在index.html中打印req.responseText, 我得到responseText=“/Tests/b.php?url=/stream/stream.m4s” Jow在b.php生成响应后修改responseTex

我有一个关于修改
xmlhttprequest
responseText
的问题

index.html
xmlhttprequest(req)
发送到
b.php
,(
index.html
b.php
都放在Tests文件夹中)

b.php
echos二进制(
video/mp4
)数据

我在
index.html
中打印
req.responseText
, 我得到
responseText=“/Tests/b.php?url=/stream/stream.m4s”

Jow在
b.php
生成响应后修改
responseText
内容。(不要修改
index.html
b.php

示例:响应写为
“/abc/Tests/b.php?url=/stream/stream.m4s”

请给我一些建议,谢谢


我简化了我的问题:如何在php完成响应生成后追加/修改响应内容。b、 php回显字符串,如“abc”。在发送到浏览器之前,通过apache(或其他)将响应字符串追加/修改为“123abc”。浏览器(请求响应文本)将获得“123abc”标记。怎么做?谢谢

将建议另一种方法:

<?php

// open the file in a binary mode
$url="./stream/stream.m4s";
$fp = fopen($url, 'rb');

// send the right headers
header("Content-Type: video/mp4");
header("Content-Length: " . filesize($url));

// dump the file and stop the script
fpassthru($fp);
exit;

?>

另外,当您进行AJAX调用时,您需要等待
成功
完成
,然后再进行操作,这样您就知道内容已传回并在DOM中呈现。由于视频文件更大,您可能会在将数据传回AJAX请求之前开始处理其他代码


需要更多的帮助吗?发布更多的代码。

欢迎来到SO,请编辑您的帖子,并添加一些代码片段,以请求b.php。您还应该看看
fpassthru()
我简化了我的问题:如何在php生成响应后追加/修改响应内容。b、 php回显字符串,如“abc”。在发送到浏览器之前,通过apache(或其他)将响应字符串追加/修改为“123abc”。浏览器(请求响应文本)将获得“123abc”标记。怎么做?谢谢现在,这就没什么意义了。我们需要更多的代码示例。
index.html
使用什么?我简化了我的问题:在php完成响应生成后,如何追加/修改响应内容。b、 php回显字符串,如“abc”。在发送到浏览器之前,通过apache(或其他)将响应字符串追加/修改为“123abc”。浏览器(请求响应文本)将获得“123abc”标记。怎么做?谢谢
<?php

// open the file in a binary mode
$url="./stream/stream.m4s";
$fp = fopen($url, 'rb');

// send the right headers
header("Content-Type: video/mp4");
header("Content-Length: " . filesize($url));

// dump the file and stop the script
fpassthru($fp);
exit;

?>