LoginSignup
15
13

More than 5 years have passed since last update.

PHPでの動画ダウンロード用ページ

Posted at
<?php

//ダウンロードさせる元ファイルパス
$source = $_POST['source'];
//ダウンロードさせる元ファイル名
$filename = $_POST['filename'];
//ファイルのIDみたいの
$itemid = $_POST['itemid'];

//ダウンロードファイル名をファイルID+元ファイル名
$j_file   = $itemid.'_'.$filename;
//必要であればエンコード
$j_file   = mb_convert_encoding($j_file, "SJIS", "EUC");

//HTTPヘッダ(コンテンツタイプ)
header("Content-Type: application/octet-stream");
//ダウンロードファイル名
header("Content-Disposition: attachment; filename=$j_file");
//ダウンロードファイルサイズ
header('Content-Length: ' . filesize($source));
//ファイルを読み込んで出力
readfile($source);
?>

主なContent-Type

文書系

テキスト文書 text/plain
CSVファイル text/csv
PDF文書 application/pdf
HTML文 text/html
スタイルシート text/css
JavaScriptファイル text/javascript

画像系

JPEG image/jpeg
PNG image/png
GIF image/gif

音声系

MP3  audio/mpeg
MP4  audio/mp4
WAV audio/x-wav
MIDI audio/midi

Content-Typeは適切に指定するための参考リンク

content-type一覧

perl の CGI や PHP でよく出力する Content-type ヘッダ一覧 (MIME-type) | perl/CGI | 阿部辰也のブログ――人生はひまつぶし。

15
13
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13