Created
March 5, 2017 13:33
-
-
Save katsuobushiFPGA/bc141ec311160a154500c72cfaea29da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>アップロードフォーム</title> | |
<script src="jquery-3.1.1.min.js"></script> | |
<script type="text/javascript"> | |
function file_upload() | |
{ | |
console.log("test"); | |
// フォームデータを取得 | |
var formdata = new FormData($('#my_form').get(0)); | |
// POSTでアップロード | |
$.ajax({ | |
url : "upload.php", | |
type : "POST", | |
data : formdata, | |
cache : false, | |
contentType : false, | |
processData : false, | |
dataType : "html" | |
}) | |
.done(function(data, textStatus, jqXHR){ | |
alert(data); | |
}) | |
.fail(function(jqXHR, textStatus, errorThrown){ | |
alert("fail"); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
PHPアップロード | |
<form method="POST" action="file2.php" enctype="multipart/form-data"> | |
ファイル: | |
<input type="file" name="uploaded" size="50" /> | |
<input type="submit" value="アップロード" /> | |
</form> | |
Ajaxアップロード | |
<form id="my_form"> | |
<input type="file" name="file_1"> | |
<button type="button" onclick="file_upload()">アップロード</button> | |
</form> | |
</body> | |
</html> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$str = './doc/'.$_FILES['uploaded']['name']; | |
$str = mb_convert_encoding($str, "SJIS", "AUTO"); | |
move_uploaded_file($_FILES['uploaded']['tmp_name'], $str); | |
echo"アップロード完了しました。"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "Hello,World"; | |
?> | |
<a href="file1.php">ここ</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 一時アップロード先ファイルパス | |
$file_tmp = $_FILES["file_1"]["tmp_name"]; | |
// 正式保存先ファイルパス | |
$file_save = "./doc/" . $_FILES["file_1"]["name"]; | |
$file_save = mb_convert_encoding($file_save, "SJIS", "AUTO"); | |
// ファイル移動 | |
$result = move_uploaded_file($file_tmp, $file_save); | |
if ( $result === true ) { | |
echo "UPLOAD OK"; | |
} else { | |
echo "UPLOAD NG"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment