FrontPage
upload.phpのソースコード
<?
require("MySmarty.class.php");
require('Settings.class.php');
$smarty = new MySmarty();
$settings = new Settings;
session_start();
$id = $_SESSION['id'];
$pass = $_SESSION['pass'];
// ユーザチェック
if( ( $id == '' ) || ( !$settings->isValidUser ($id,$pass) ) ){
header("Location: login.php" );
exit;
}
$topicid = $_GET['topicid'];
if( $topicid == '' ){
$topicid = $_POST['topicid'];
}
// if( $topicid == '' ){ exit; }
$settings->loadSettings();
$smarty->assign( "maintitle", $settings->maintitle );
$smarty->assign('topicid', $topicid);
// アップロード先ディレクトリの指定
$uploaddir = 'archives/';
// トピック編集画面より呼び出し
if( $_SERVER['REQUEST_METHOD'] == 'GET' ){
$temp_file = "upload.html";
// アップロード画面より呼び出し
} else if( $_POST['upload'] <> '' ){
if( $_FILES['upfile']['size'] >0 ){
// ディレクトリの作成
@mkdir( $uploaddir, 0777 );
if( file_exists( $uploaddir ) ){
$wok = pathinfo( $_FILES['upfile']['name'] );
$uploadfile = $uploaddir . $wok['basename'];
$ext = strtolower($wok['extension']);
if( file_exists( $uploadfile ) ){
$err_msg = "同一名称のファイルがあります($uploadfile)。名称を変更して再アップロードしてください。";
$temp_file = "upload.html";
} else {
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) {
$temp_file = "upload2.html";
$imgflg = 0;
if( $ext == 'gif'){ $imgflg=1; }
else if( $ext == 'jpg'){ $imgflg=1; }
else if( $ext == 'jpe'){ $imgflg=1; }
else if( $ext == 'jpeg'){ $imgflg=1; }
else if( $ext == 'png'){ $imgflg=1; }
else if( $ext == 'bmp'){ $imgflg=1; }
else if( $ext == 'tif'){ $imgflg=1; }
else if( $ext == 'tiff'){ $imgflg=1; }
if( $imgflg == 1 ){
$html = "<img src="$uploadfile">";
} else {
$html = "<a href="$uploadfile">Download file</a>";
}
$temp_file = "upload2.html";
} else {
$err_msg = "ファイルをアップできません。パーミッションを確認してください。";
$temp_file = "upload.html";
}
}
} else {
$err_msg = "フォルダが作成できません。パーミッションを確認してください。";
$temp_file = "upload.html";
}
} else {
$err_msg = "ファイルが指定されていないか、空です。";
$temp_file = "upload.html";
}
$smarty->assign('html', $html);
} else {
$temp_file = "upload.html";
}
$smarty->assign('error_message', $err_msg);
$smarty->assign('general_message', $gen_msg);
$smarty->display( $temp_file );
?>