ようこそ! このブログは、PHPとMysqlを使って作成したオリジナルプログラムを、QHMに読み込んで表示させています。

upload.php

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 = "&lt;img src=&quot;$uploadfile&quot;&gt;";
			} else {
				$html = "&lt;a href=&quot;$uploadfile&quot;&gt;Download  file&lt;/a&gt;";
			}
			$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 );

?>

powered by Quick Homepage Maker 4.25
based on PukiWiki 1.4.7 License is GPL. QHM

最新の更新 RSS  Valid XHTML 1.0 Transitional