2012-04-08 8 views
3

私の電子ブックリーダー(Sony PRS-T1)の内蔵ブラウザーは非常に愚かで、ダウンロードする代わりに.epubファイルをテキストファイルとして開くため、この.htaccessファイルでの.epubファイルをダウンロードするには、ブラウザを強制しようとした:ヘッダーadd Content-Disposition "attachment"が内部サーバーエラーを引き起こします

<FilesMatch "\.(?i:epub)$"> 
    ForceType application/octet-stream 
    Header add Content-Disposition "attachment" 
</FilesMatch> 

はしかし、これは内部サーバーエラーが発生:私はHeader add Content-Disposition "attachment"を除外すると、エラーが

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

ありませんが - ただし、ブラウザはファイルをダウンロードしませんでした:(

何か間違っていますか?内部サーバーエラーはどこから発生しますか?

[EDIT 2013年4月11日]

私はいくつかの情報を追加することを思い出し、このスレッドは、「人気の質問バッジ」を獲得しました。

私は最終的に以下のPHPの機能とソニーのPRS-T1ブラウザ上でダウンロードを強制するために管理

function startDownload($path, $mimeType) { 
if(!file_exists($path)) { 
// File doesn't exist, output error 
exit('file not found'); 
} else { 
$size = filesize($path); 
$file = basename($path); 

// Set headers 
header("Pragma: public"); // required 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Cache-Control: private",false); // required for certain browsers 
header("Content-Description: File Transfer"); 
header("Content-Disposition: attachment; filename=\"$file\""); 
header("Content-Type: $mimeType"); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: $size"); 
// Read the file from disk 
readfile($path); 
} 

exit(); 
} 

・ホープ1日誰かを助けること。

+0

あなたのログは言う解決

sudo a2enmod headers 

問題...? –

+0

申し訳ありませんが、私のサーバーではありません - おそらく私はログを要求することはできますが、実際にはわかりません。 – speendo

+1

[Content-Dispositionヘッダーを特定のディレクトリのファイルにのみ添付ファイルに設定する]の可能な複製?](http://stackoverflow.com/questions/3977159/set-content-disposition-header-to-attachment-only-on- files-in-a-certain-director) –

答えて

3

これが答えかもしれません:

http://diogomelo.net/node/24

The module headers is not enabled by default on Apache. So, we have to enable it manually.

To enable this module, log in as root, and create a symbolic link from mods-available/headers.load to mods-enabled. After that, reload apache and it's done. To do so, I've used this commands.

su - cd 
/etc/apache2/mods-enabled/ ln -s ../mods-available/headers.load 
headers.load sh /etc/init.d/apache2 force-reload 
+0

これはWindows上のApacheでどのように達成できますか? – Gregra

+2

@Gregraオープン 'httpd。conf'を削除し、 '# '文字を削除して' LoadModule headers_module modules/mod_headers.so'という行のコメントを外します。次に、Apacheサーバーを再起動します。 – Farahmand

1

ます。また、ヘッダーモジュールは、あなたのhtaccessファイルでこれを使用する前に、有効になっていることを確認することをお勧めします。ヘッダモジュールが有効でない場合、次の行は、エラーが生成されます。

<IfModule mod_headers.c> 
    <FilesMatch "\.(mp3|MP3)$"> 
     ForceType audio/mpeg 
     Header set Content-Disposition "attachment" 
     Allow from all 
    </FilesMatch> 
</IfModule> 

注:ここ

Header set Content-Disposition "attachment" 

はmp3ファイルの強制ダウンロードがヘッダモジュールが有効になっている場合にのみ、という例だことがありませんモジュールを有効にしない場合、モジュールが有効でない場合、IfModuleタグ内の何かを無視します。

apacheモジュールを有効にするには、httpd.confファイルを編集するか、wampサーバーでwampトレイアイコンをクリックし、 "Apache - > Apache Modules - > headers_module"を選択するか、チェックされていることを確認します。 Ubuntuのための

0

は、使用して、apache2のヘッダモジュールを有効にするには、ショートカットtheresのです^ _^

関連する問題