
move_uploaded_file($_FILES[“upfile”][“tmp_name”], “files/” . $_FILES[“upfile”][“name”]で、画像をアップロード
form.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sample</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
ファイル:<br>
<input type="file" name="upfile" size="30" /><br>
<input type="submit" value="アップロード" />
</form>
</body>
</html>
upload.php
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf8">
<title>画像アップロード</title>
</head>
<body>
<p><?php
if (is_uploaded_file($_FILES["upfile"]["tmp_name"])){
if (move_uploaded_file($_FILES["upfile"]["tmp_name"], "files/" . $_FILES["upfile"]["name"])){
chmod("files/" . $_FILES["upfile"]["name"], 0644);
echo $_FILES["upfile"]["name"] . "をアップロードしました。";
} else {
echo "ファイルをアップロードできません。";
}
} else {
echo "ファイルが選択されていません。";
}
?></p>
</body>
</html>