PHP auの3g2, amcファイルをダウンロードさせるスクリプト
auの3g2, amcファイルをダウンロードさせるスクリプト
ちょこっとメモ。
<?php $fileName = "test"; $fileExt = "3g2";//or amc $filePath = "/home/data/$fileName.$fileExt"; $fileSize = filesize( $filePath ); if( ! isset( $_SERVER['HTTP_RANGE'] ) ){ header( "Content-Disposition: inline; filename=\"$fileName.$fileExt\"" ); header( "Content-Length: $fileSize" ); if( $fileExt == "3g2" ){ header( "Content-Type: audio/3gpp2" ); } elseif( $fileExt == "amc" ){ header( "Content-Type: application/x-mpeg" ); } readfile( $filePath ); exit; } else{ list( $range1, $range2 ) = explode( "-", substr( $_SERVER['HTTP_RANGE'], 6 ) ); $len = $range2 - $range1 +1; $fp = fopen( $filePath, "rb" ); $buf = fread( $fp, ( $range2 +1 ) ); fclose( $fp ); $buf = substr( $buf, $range1 ); header( "HTTP/1.1 206 Partial content" ); header( "Last-Modified: ".date("D, j M Y G:i:s \\G\\M\\T") ); header( "Pragma: no-cache" ); header( "Accept-Ranges: bytes" ); header( "Content-Length: $len" ); header( "Content-Range: bytes ${range1}-${range2}/${size}" ); if( $fileExt == "3g2" ){ header( "Content-Type: audio/3gpp2" ); } elseif( $fileExt == "amc" ){ header( "Content-Type: application/x-mpeg" ); } print( $buf ); exit; } ?>