File "download.php"

Full path: /www/arduino_gps/download.php
File size: 2.68 KiB (2743 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
//■ファイルダウンロードプログラム

//●文字コードの設定
// ブラウザ表示文字コード
$enc_disp = "SJIS";

// 保存ファイル名文字コード
$enc_file = "UTF-8";

//●ダウンロードするフォルダの場所を設定
$dir_name = "/www/arduino/" .$_GET['no'] ."/data/" .$_GET['Mname'];

//●ダウンロードするファイルの情報を取得
EXTRACT($_GET);

//●ダウンロードするファイル名を設定
$file_name = urldecode($_GET["f"]);

//●ダウンロードするファイルの場所を設定
$path = $dir_name . "/" .$file_name;

//●ダウンロードしたファイル名をテキストファイルに保存(履歴として残す)
$fpp = fopen("testlog.txt","a");
fwrite($fpp,$path ."\n");
fclose($fpp);

//●ダウンロードするファイルの拡張子を取得
$finfo = pathinfo($path);
$ext = $finfo["extension"];


//●拡張子からファイルの種類を設定


header("Content-Type: image/jpeg");

switch ($ext)
{
	case "mpg":
	case "mpeg":
		header("Content-Type: video/mpeg");
		break;

	case "wmv":
		header("Content-Type: video/x-ms-wmv");
		break;

	case "swf":
		header("Content-Type: application/x-shockwave-flash");
		break;

	case "mp3":
		header("Content-Type: audio/mpeg");
		break;

	case "mp4":
		header("Content-Type: audio/mp4");
		break;

	case "wav":
		header("Content-Type: audio/x-wav");
		break;

	case "mid":
	case "midi":
		header("Content-Type: audio/midi");
		break;

	case "mmf":
		header("Content-Type: application/x-smaf");
		break;

	case "jfif":
	case  "jpe":
	case  "jpeg":
	case  "jpg":
		header("Content-Type: image/jpeg");
		break;

	case "gif":
		header("Content-Type: image/gif");
		break;

	case "png":
		header("Content-Type: image/png");
		break;

	case "tif":
		header("Content-Type: image/tif");
		break;

   case "pdf":
         header("Content-Type: application/pdf");
         break;

	case "htm":
	case "html":
		header("Content-Type: text/html");
		break;

	case "xls":
		header("Content-Type: application/vnd.ms-excel");
		break;

	case "doc":
		header("Content-Type: application/msword");
		break;

	case "ppt":
		header("Content-Type: application/vnd.ms-powerpoint");
	 	break;

	default:
		header("Content-Type: application/octet-stream");
		break;
}

//●ファイル名の文字コードを変換する
/*
$det_enc = mb_detect_encoding($file_name, $enc_file . ", " . $enc_disp);
if ($det_enc  and $det_enc !=  $enc_disp)
{
	$file_name = mb_convert_encoding($file_name,  $enc_disp, $det_enc);
}
*/
//●ファイルダウンロード処理
header("Content-Disposition: attachment; filename=".   $file_name);
$fp = fopen($path, "rb");
$data = fread($fp, filesize($path));
echo $data;
fclose($fp);

?>

PHP File Manager