0

content-disposition を設定し、指定されたファイルをブラウザに強制的にダウンロードさせる openfile.php という非常に単純なファイルがあります。

FF では問題なく動作しますが、Safari では奇妙な .xhtml ファイルをダウンロードします。詳しく調べると、このファイルが発生するデフォルトのエラー ページのように見えます。

IE では、このエラー ページが表示されます。

ここで何が起こっているのか誰でも推測できますか?

ここにリンクがあります: http://hqinternetsolutions.com/Websites/Fabric%20Traditions/?page_id=215

これはファイルを開くコードです

<?php
if ( ! isset($_GET['file']) )
    die();

if ( strpos( $_GET['file'], (isset($_SERVER['HTTPS']) ? 'https|' : 'http|') . $_SERVER['SERVER_NAME'] ) === false )
    die();

require_once('../lib/class.mimetype.php');
$mime = new mimetype();

$fPath = str_replace('http|', 'http://', $_GET['file']);
$fPath = str_replace('https|', 'https://', $fPath);
$fType = $mime->getType( $fPath );
$fName = basename($fPath);

$origname = preg_replace('/_#_#\d*/','',$fName);

$fContent = fetch_content( $fPath );

output_content( $fContent, $origname );

function fetch_content( $url ) {
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_HEADER, 0 );

    ob_start();

    curl_exec( $ch );
    curl_close( $ch );

    $fContent = ob_get_contents();

    ob_end_clean();

    return $fContent;
}

function output_content( $content, $name ) {
    header( "Expires: Wed, 9 Nov 1983 05:00:00 GMT" );
    header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
    header( "Content-Disposition: attachment; filename=" . $name );
    header( "Content-type: application/octet-stream" );
    header( "Content-Transfer-Encoding: binary" );

    echo $content;
}
?>
4

3 に答える 3

1

あなたのヘッダーは

Content-Disposition: attachment; filename=Pillow1.pdf

しかし、そうあるべきです

Content-Disposition: attachment; filename="Pillow1.pdf"

Windowsを使用していないため、これが問題かどうかはわかりません。

于 2011-12-28T23:08:43.497 に答える
0

Firefox でもリンクが機能しません。ダウンロードされるコンテンツは HTML ページです。

送信しているヘッダーを見る ( http://redbot.org/?uri=http%3A%2F%2Fhqinternetsolutions.com%2FWebsites%2FFabric%2520Traditions%2Fwp-content%2Fplugins%2Fwp-publication-archive%2Fincludes%2Fopenfile .php%3Ffile%3Dhttp|hqinternetsolutions.com%2FWebsites%2FFabric%2520Traditions%2Fwp-content%2Fuploads%2F2011%2F12%2FPillow1.pdf ) 注意:

  • Expires ヘッダーが壊れている
  • HTTP には Content-Transfer-Encoding はありません
  • Content-Type は PDF のタイプである必要があります

(ただし、間違ったコンテンツが送信される理由を説明するものはありません)

于 2011-12-29T08:35:59.943 に答える
0

この PHP が機能しない理由は%20、URL にあるためです。スペースを含めることはできません。そうしないと、スクリプト内の区切り文字ファインダーが失敗します。

于 2011-12-29T23:30:30.950 に答える