![](/img/trans.png)
[英]Cannot show loading image while javascript and php script are loading
[英]PHP image headers and JavaScript loading
我在fancybox中顯示圖像時遇到大問題。 圖像由PHP使用header()
和readfile()
“生成”。
當我直接從瀏覽器訪問腳本時,一切正常,但是當請求來自fancybox JavaScript時,瀏覽器突然停止響應,並且在加載內容區域中長時間放置后,我得到了二進制代碼而不是圖像。
這是代碼:
ob_clean();
header('Content-Type: '.$post->post_mime_type);
$name = basename($post->guid);
$base = home_url();
$path= $_SERVER{'DOCUMENT_ROOT'}.str_replace($base,'',$post->guid);
header ('Content-Disposition: inline; filename='.$name);
header ('Content-length: ' .filesize($path));
readfile($path);
加載到fancybox中的內容屏幕: http : //img502.imageshack.us/img502/8535/screenq.png
輸出的前4個字節看起來像一個有效的PNG標頭。
請確認$ post-> post_mime_type為“ image / png”。
我不知道該框架,它可能會因不常見的“ Content-Disposition:inline”標題而感到困惑,請刪除該行。
FancyBox從URL猜測內容類型,但有時可能是錯誤的。 解決方案是強制>您的類型,例如-$(“。selector”)。fancybox({'type':'image'}); (要求版本1.3+)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.