我想上傳文件在服務器上的JavaScript,雖然,將圖像上傳到服務器通過JavaScript
<script>
function SubmitFormData9() {
var fileToUpload1 = $("#fileToUpload1").val();
var fileToUpload2 = $("#fileToUpload2").val();
var resumeid9 = $("#resumeid9").val();
$.post("r_nine.php", { fileToUpload1: fileToUpload1 , fileToUpload2: fileToUpload2 , resumeid9 : resumeid9 },
function(data) {
$('#results').html(data);
$('#myForm9')[0].reset();
});
}
</script>
<form id="myForm9" method="post" enctype="multipart/form-data">
<input class="form-control" type="file" name="fileToUpload1" id="fileToUpload1" >
<input class="form-control" type="file" name="fileToUpload2" id="fileToUpload2" >
<input id="resumeid9" name="resumeid9" type="hidden" value="<? echo $resumeid;?>"/>
<input type="button" class="btn btn-rounded btn-primary btn-sm" id="submitFormData9" onclick="SubmitFormData9();" value="Submit" />
</form>
,但我無法從形式值傳遞給r_nine.php頁
守則r_nine。 PHP頁面
$resumeid9 = $_POST['resumeid9'];
$target_dir = "reqdoc/";
$target_file = $target_dir . basename($_FILES["fileToUpload1"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$new_filename1 = $target_dir . uniqid() . '.' . $imageFileType;
if (move_uploaded_file($_FILES["fileToUpload1"]["tmp_name"], $new_filename1))
{
$filee1 = $new_filename1;
}
$target_dir = "reqdoc2/";
$target_file = $target_dir . basename($_FILES["fileToUpload2"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$new_filename = $target_dir . uniqid() . '.' . $imageFileType;
if (move_uploaded_file($_FILES["fileToUpload2"]["tmp_name"], $new_filename))
{
$filee = $new_filename;
}
$sql1="UPDATE resume set resume='".$filee1."',tracker_file='".$filee."' WHERE id='".$resumeid9."' ";
if(mysqli_query($con,$sql1))
{
//echo "Files Saved Successfully";
}
else
{
die('Error:' . mysqli_error($con));
}
誰能告訴如何糾正上面的代碼,這樣我可以上傳數據
您需要使用'enctype =「multipart/form-data」'來上傳文件。並在ajax中使用'var formData = new FormData($(this)[0]);' – Saty
[上傳兩個數據和文件在一種形式使用Ajax?](http://stackoverflow.com/questions/10899384 /上傳兩個數據和文件在一個形式使用ajax) – Saty
而不是兩個文件類型使用一個與多個圖像上傳 –