0 レビュー
0 回答
php-CloudFlareを介してgzip圧縮されたファイルをダウンロードします
PHPファイルプロテクタースクリプトがあります:
.htaccess
RewriteEngine on
RewriteRule ^(.*).(zip|tgz)$ ../wp-file-protector.php?file=$1.$2 [QSA]
wp-file-protector.php
<?php
global $wpdb;
/** Make sure that the WordPress bootstrap has run before continuing. */
require( dirname(__FILE__) . '/wp-load.php' );
$current_user = wp_get_current_user();
if ($current_user->ID > 0){
$order = $_GET['order'];
$items = new_get_order_by_id_and_user($order, $current_user->ID);
if($items != false){
$file_enabled = true;
//Some authentication
$filepath = dirname(__FILE__).'/../downloads/'.$_GET['file'];
if($file_enabled && file_exists($filepath)){
$filename = basename($filepath);
$extension = end(explode('.', $filename));
ob_clean();
// http headers for zip downloads
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
if($extension == 'tgz'){
header("Content-Type: application/gzip");
}else{
header("Content-type: application/octet-stream");
}
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath));
ob_end_flush();
@readfile($filepath);
}
}
}
zipファイルやその他のファイルで問題なく動作します。この問題はgzip圧縮されたファイルで発生します。予期しない結果が発生しました(Firefoxのダウンロードとオープンアクションでも異なる結果が得られました)。
gzip圧縮されたファイルには適切なヘッダーが必要だと思います。何を使うべきですか?
リクエストがCloudflareサービスを介して実行されていることも知っておくとよいので、Cloudflareサーバーにgzipで圧縮しないように指示するヘッダーを送信する必要があるかもしれません。
行き詰まっている:(
アップデート#1
header("Content-type: application/x-gzip");
header("Content-type: application/x-gzip");
これも機能しません。 Firefoxで保存を選択すると、破損したファイルを開くときに通知されます。 [開く]を選択すると、拡張子のないファイルが表示されますが、ディレクトリの奥深くに入ることができるため、タールのように見えます。
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。