フォームのコミットと受信ファイルのコミットと受信
20269 ワード
フォームの作成
フォーム受信
ファイルフォームの作成
ファイルを受信して保存
<html>
<body>
<div>--------------get--------------------</div>
<form action="/server.php" method="get" target="_blank">
checkbox<input type='checkbox' name='checkbox' value='checkbox'></input><br>
radio<input type='radio' name='radio' value='radio'></input><br>
image<input type='image' name='image' value='image'></input><br>
text<input type='text' name='text' value='text'></input><br>
password<input type='password' name='password' value='password'></input><br>
hidden<input type='hidden' name='hidden' value='hidden'></input><br>
button<input type='button' name='button' value='button'></input><br>
reset<input type='reset' name='reset' value='reset'></input><br>
submit<input type='submit' name='submit' value='submit'></input><br>
</form>
<div>--------------post--------------------</div>
<form action="/server.php" method="post" target="_blank">
checkbox<input type='checkbox' name='checkbox' value='checkbox'></input><br>
radio<input type='radio' name='radio' value='radio'></input><br>
image<input type='image' name='image' value='image'></input><br>
text<input type='text' name='text' value='text'></input><br>
password<input type='password' name='password' value='password'></input><br>
hidden<input type='hidden' name='hidden' value='hidden'></input><br>
button<input type='button' name='button' value='button'></input><br>
reset<input type='reset' name='reset' value='reset'></input><br>
submit<input type='submit' name='submit' value='submit'></input><br>
</form>
</body>
</html>
フォーム受信
<?php
if(isset($_GET["submit"]))
{
echo "<div>----- get ------</div>";
foreach($_GET as $tp)
{
echo "$tp <br>";
}
}
if(isset($_POST["submit"]))
{
echo "<div>----- post ------</div>";
foreach($_GET as $tp)
{
echo "$tp <br>";
}
}
?>
ファイルフォームの作成
<html>
<body>
<form action="/server.php" method="post" target="_blank" enctype="multipart/form-data">
<input type="file" name="picture"></input>
<input type="submit" name="upload"></input>
</form>
</body>
</html>
ファイルを受信して保存
<?php
//
if ($_FILES["picture"]["error"] > 0)
{
echo "Error: " . $_FILES["picture"]["error"] . "<br />";
}
else
{
//
echo "succeed!<br>";
echo "Upload: " . $_FILES["picture"]["name"] . "<br />";
echo "Type: " . $_FILES["picture"]["type"] . "<br />";
echo "Size: " . ($_FILES["picture"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["picture"]["tmp_name"]. "<br />";
//
if (file_exists( $_FILES["picture"]["name"]))
{
echo $_FILES["picture"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["picture"]["tmp_name"],$_FILES["picture"]["name"]);
echo "Stored in: ".$_FILES["picture"]["name"];
}
}
?>