ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
PHP でファイルアップロード ( 含 HTML5 の multiple="true" )
日時: 2011/05/22 15:24
名前: lightbox



初心者用フォームスケルトン : ファイルアップロード

拡張子:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>初心者用フォームスケルトン : SQL、メール、Twitter</title>
<script type="text/javascript">
function resetIframe() {
	var ifdoc = document.getElementById("result").contentWindow.document;
	ifdoc.write("");
	ifdoc.close();
}
</script>
</head>
<body>
<div style='position:relative;padding:10px;'>
<span style='font-size:20px;'>初心者用フォームスケルトン</span>
<input
	type="button"
	value="結果をリセット"
	onclick='resetIframe();'
	style='position:relative;top:-3px;'
/>
<input
	type="button"
	value="ページリセット"
	onclick='location="form.htm"'
	style='position:relative;top:-3px;'
/>
<br><br>

<table style='width:100%'><tr>
<td style='width:1px;vertical-align:top;width:300px;'>
<form
	enctype="multipart/form-data"
	action="upload1.php"
	method="POST"
	target="result"
	style='display:inline;'
>
	<input type="hidden" name="MAX_FILE_SIZE" value="100000">
	<input
		type="file"
		id="file_1"
		name="file_1"
		size="40"
	/>
	<br>
	<input
		type="submit"
		value="単フィールド単ファイルアップロード"
	/>
	<br />
	<br />
</form>

<form
	enctype="multipart/form-data"
	action="upload2.php"
	method="POST"
	target="result"
	style='display:inline;'
>
	<input type="hidden" name="MAX_FILE_SIZE" value="100000">
	<input
		type="file"
		id="file_1"
		name="file_1"
		size="40"
	/>
	<br>
	<input
		type="file"
		id="file_2"
		name="file_2"
		size="40"
	/>
	<br>
	<input
		type="submit"
		value="複フィールド複ファイルアップロード"
	/>
	<br />
	<br />
</form>

<form
	enctype="multipart/form-data"
	action="upload3.php"
	method="POST"
	target="result"
	style='display:inline;'
>
	<input type="hidden" name="MAX_FILE_SIZE" value="100000">
	multiple="true"<br>
	<input
		type="file"
		id="file_1"
		name="file_up[]"
		size="40"
		multiple="true"
	/>
	<br>
	<input
		type="submit"
		value="単フィールド複ファイルアップロード"
	/>
	<br />
	<br />
</form>



</td><td>
<iframe
	id="result"
	name="result"
	frameborder="1"
	scrolling="yes"
	style='width:100%;height:700px;'
></iframe>
</td>
</tr>

</table>
</div>
</body>
</html>
メンテナンス

単フィールド単ファイルアップロード ( No.1 )
日時: 2011/05/22 15:17
名前: lightbox


日時: 2011/05/22 15:17
名前: lightbox
拡張子:
<?
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

foreach( $_POST as $Key => $Value ) {
	$_POST[$Key] = str_replace("\\\\", "\\", $Value );
	$_POST[$Key] = str_replace("\\'", "'", $_POST[$Key] );
	$_POST[$Key] = str_replace("\\\"", "\"", $_POST[$Key] );
}

print "<pre>";
print_r( $_FILES );
print "</pre>";

$target = $_FILES['file_1']['name'];

$upload = "./upload_file/";
$upload .= $target;
print $upload . "<br>";

if ( move_uploaded_file( $_FILES['file_1']['tmp_name'], $upload ) ) {
	print "アップロードに成功しました\n";
}
else {
	print "アップロードに失敗しました\n";
}

?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
複フィールド複ファイルアップロード ( No.2 )
日時: 2011/05/22 15:17
名前: lightbox
拡張子:
<?
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

foreach( $_POST as $Key => $Value ) {
	$_POST[$Key] = str_replace("\\\\", "\\", $Value );
	$_POST[$Key] = str_replace("\\'", "'", $_POST[$Key] );
	$_POST[$Key] = str_replace("\\\"", "\"", $_POST[$Key] );
}

print "<pre>";
print_r( $_FILES );
print "</pre>";


foreach( $_FILES as $Key => $Value ) {

	$target = $_FILES[$Key]['name'];
	$upload = "./upload_file/";
	$upload .= $target;
	print $upload . "<br>";

	if ( move_uploaded_file( $_FILES[$Key]['tmp_name'], $upload ) ) {
		print "アップロードに成功しました<br>\n";
	}
	else {
		print "アップロードに失敗しました<br>\n";
	}
}

?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
単フィールド複ファイルアップロード ( No.3 )
日時: 2011/05/22 15:18
名前: lightbox
拡張子:
<?
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

foreach( $_POST as $Key => $Value ) {
	$_POST[$Key] = str_replace("\\\\", "\\", $Value );
	$_POST[$Key] = str_replace("\\'", "'", $_POST[$Key] );
	$_POST[$Key] = str_replace("\\\"", "\"", $_POST[$Key] );
}

print "<pre>";
print_r( $_FILES );
print "</pre>";


foreach( $_FILES['file_up'][name] as $Key => $Value ) {

	$target = $_FILES['file_up']['name'][$Key];
	$upload = "./upload_file/";
	$upload .= $target;
	print $upload . "<br>";


	if ( move_uploaded_file( $_FILES['file_up']['tmp_name'][$Key], $upload ) ) {
		print "アップロードに成功しました<br>\n";
	}
	else {
		print "アップロードに失敗しました<br>\n";
	}


}

?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス