Commit a5e14659 authored by 君塚 悠's avatar 君塚 悠

プログラム作成(upload.php,upload_save.php:ファイルのアップロード)

parent e7934b3b
<?php
$header_info="Form: ".$_POST['_from']."
\nContent-Type: text/plain;carset
=ISO-2022-JP\nX-Mailer: PHP/".phpversion();
$body="■■".$_POST['_subject']."■■\n\n";
foreach ($_POST as $key=>$value) {
if (!strstr($key,"_")) {
$body.="[".$key."]".$value."\r\n";
}
}
mb_send_mail($_POST['_email'], $_POST['_subject']
, $body, $header_info);
header("Location: ".$_POST['_result']);
?>
\ No newline at end of file
<html>
<head>
<title>ファイルのアップロード</title>
</head>
<body>
<h1 style="background:#cccccc">ファイルのアップロード</h1>
<form method="post" action="upload_save.php"
enctype="multpart/form-data">
<input type="hidden" name="max_file_size"value=1000000" />
<input type="file" name="upload_file size="70"><br />
(上書き禁止)
<input type="checkbox" name="forbidden"value="1" checked />
<input type="submit" value="アップロード" />
</form>
</body>
</html>
\ No newline at end of file
<?php
$error_flag=FALSE;
$name="/\doc/".$_FILES['upload_file']['name'];
if (file_exists($name)==TRUE & $_POST['forbidden']==1) {
$error_flag=TRUE;
$error_msg="同名のファイルが存在します。";
} elseif ($_FILES['upload_file']['error'] != UPLOAD_ERR_OK) {
$error_flag=TRUE;
switch ($_FILES['upload']['error']) {
case UPLOAD_ER_FORM_SIZE :
$error_msg="php.iniのupload_max_filesize制限を越えています。";
break;
case UPLOAD_ERR_FORM_SIZE :
$error_msg="HTMLのMAX_FILE_SIZE制限を越えています。";
break;
case UPLOAD_ERR_PARTIAL :
$error_msg="ファイルが一部しかアップロードされていません。";
break;
case UPLOAD_ERR_NO_FILE :
$error_msg="ファイルはアップロードされていませんでした。";
break;
default :
$error_msg="不明なエラーです。";
break;
}
}
if ($error_flag) {
print("<div style='color:Red;'>".$error_msg."</div>");
} else {
move_uploaded_file($_FILES['upload_file']['tmp_name'],$name);
}
?>
<html>
<head>
<title>ファイルのアップロード</title>
</head>
<body>
<h1 style="background:#cccccc">ファイルアップロード(処理結果)</h1>
<table border="1">
<tr>
<th>ファイル</th><th>サイズ</th><th>最終アクセス日</th><th>最終更新日</th>
</tr>
<?php
clearstatcache();
$o_dir=opendir("./doc/");
while ($file=readdir($o_dir)) {
if ($file!="." && $file!="..") {
?>
<tr>
<td><a href="./doc/<?php print($file); ?>"><?php print($file); ?> </a></td>
<td><?php print(round(filesize("./doc/".$file)/1024)); ?>KB</td>
<td><?php print print(data("Y/m/d H:i:s",fileatime("./doc/".$file))); ?></td>
<td><?php print print(data("Y/m/d H:i:s",filemtime("./doc/".$file))); ?></td>
<tr>
<?php
}
}
closedir($o_dir);
?>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment