単純なファイルアップロードサービスを作成しようとしていますが、JavaScript、jQuery、PHP、およびAJAX(またはこれらの言語の一部)を使用してファイルをアップロードする方法が必要です。私はホームページを設定したので、1つのファイル(フォルダではない)しかアップロードできないようにして、6つの乱数と文字のランダムなディレクトリ名を作成します。それは、作成したディレクトリの中にそのファイルをアップロードします。私はAJAXやn00bのようなものは一つも知らない。誰か助けてください。ここに私のファイルはJavaScriptとPHPを使用したAJAX POSTのアップロードファイル
のindex.phpです:
<!DOCTYPE html>
<HTML lang="en">
<head>
<title>Anonymous File Uploading</title>
<link rel="stylesheet" href="./css/bootstrap.css">
<link rel="stylesheet" href="./css/custom.css">
<script src="./js/jquery.js"></script>
<script src="./js/bootstrap.js"></script>
</head>
<script>
function upload() {
if (document.getElementById("file-upload").value == "") {
alert("Please upload a file first!");
} else {
if (!document.getElementById("terms").checked) {
alert("You must accept the terms and conditons before you can upload files.");
} else {
jQuery.ajax({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
bar.width("100%");
percent.html("100%");
status.html(xhr.responseText);
}
});
}
}
}
</script>
<body>
<div class="container top-padded">
<div class="well">
<h2 class="header">Anonymous File Uploading</h2>
<input type="file" class="file-upload" id="file-upload"></input>
<input type="checkbox"> I agree to the <a href="./terms.txt">terms and conditions</a> of using this site.</input><br>
<div class="spacer"></div>
<button class="btn btn-default center-block" onclick="upload();" id="terms">Upload</button>
</div>
</div>
</body>
</HTML>
POST.php:
file blank (i dont know how to code ajax)