Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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_Header_Foreach - Fatal编程技术网

Php 循环,一组标题和。。。什么也没发生

Php 循环,一组标题和。。。什么也没发生,php,header,foreach,Php,Header,Foreach,我正在做一个有文件上传的项目。这些文件被赋予一个随机名称,并放置在web目录的外侧 然后我有一个脚本,它根据URL中传递的参数检索这个图像,这个脚本工作得非常好 然而,我制作了一个我想传递给浏览器的标题数组,然后用foreach循环遍历这些标题,它们似乎没有设置任何内容。但是,如果我使用标题功能手动设置它们,它们就会工作!奇怪 现在,我不介意使用header函数,而不是在它们之间循环,但是,有没有一个具体的原因导致这不起作用 我还使用上述方法将我的所有标题存储在一个数组中,然后在将内容交付给浏览

我正在做一个有文件上传的项目。这些文件被赋予一个随机名称,并放置在web目录的外侧

然后我有一个脚本,它根据URL中传递的参数检索这个图像,这个脚本工作得非常好

然而,我制作了一个我想传递给浏览器的标题数组,然后用
foreach
循环遍历这些标题,它们似乎没有设置任何内容。但是,如果我使用
标题
功能手动设置它们,它们就会工作!奇怪

现在,我不介意使用
header
函数,而不是在它们之间循环,但是,有没有一个具体的原因导致这不起作用

我还使用上述方法将我的所有标题存储在一个数组中,然后在将内容交付给浏览器时对其进行处理,但是,我无法确定它们是否真的被传递,请看前面提到的问题

我的代码片段:

// Expiry date in seconds, in this instance a year
$expiry_date=   ( 60 * 60 * 24 * 365 );
// Our headers
$img_headers=   array(
    'Content-Type : ' . $mime,
    'Cache-Control: no-cache, must-revalidate',
    //'Cache-control: max-age=' . $expiry_date,
    'Expires:' . gmdate( DATE_RFC1123, time() + $expiry_date ),
    'Pragma: ',
    'Last-Modified: ' . gmdate( gmdate( DATE_RFC1123 ), filemtime( $image_path ) ),
    'Content-Length: ' . ( string ) filesize( $image_path ),
    'Content-Disposition: inline; filename="' . $image_name . '"'
);            

/*header( 'Content-Type: ' . $mime, TRUE );
header( 'Cache-Control: no-cache, must-revalidate', TRUE );
header( 'Expires: ' . gmdate( DATE_RFC1123, time() + $expiry_date ) );
header( 'Pragma: ', TRUE );
header( 'Last-Modified: ' . gmdate( gmdate( DATE_RFC1123 ), filemtime( $image_path ) ), TRUE );
header( 'Content-Length: ' . ( string ) filesize( $image_path ), TRUE );*/

// Loop through and set up our headers!
foreach( $img_headers as $new_header )
{
    header( $new_header, TRUE );
}

// Read our image and end the rest of the file execution
return die( readfile( $image_path ) );
有什么看起来不合适的吗


提前谢谢

尝试用以下内容替换foreach循环,我曾经遇到过一个类似的问题,即空格会产生逻辑错误,值得一试

foreach( $img_headers as $new_header )
{
    header( trim($new_header), TRUE );
}

这两种方法应该是相同的。可能是“内容类型:”中的额外空间导致了问题

废话,我有点自以为是的评论!真不敢相信我错过了这么一个简单的错误!唉,非常感谢!我现在觉得自己很愚蠢!呵呵