如何在 php 代码中找到输入?
How can find inputs in php codes?
我在 jQuery 中使用 $.ajax
从数据库中获取一些输入,当用户单击按钮时它会出现:
HTML
<div id="div1"></div>
<input type="button" id="button1"/>
JQuery
$("#button1").click(function() {
$.ajax({
type: 'POST',
url: "get.php",
data: {vals: "send"},
success : function(response) {
$("#div1").append(response);
}});
})
将元素导入到div后,将有一个input type="file"
像这样:
编辑:
我的表单代码在这里:
HTML
<input name="upload1" id="upload1" type="file"/>
<input type="button" value="submit" id="button2"/>
JQuery
$("#button2").click(function() {
$.ajax({
type: 'POST',
url: "uploadPhoto.php",
data: {filename: filename},
success : function(response) {
alert(response);
}
});
})
PHP
$filename = $_POST['filename '];
$target_dir = "image/";
$target_file = $target_dir . $filename;
var $src_temp = $_FILES["upload1"]["tmp_name"];
if (move_uploaded_file($src_temp, $target_file)) {
echo 'success';
}
结束编辑 1
当我想为这个按钮获取 $_FILES["upload1"]["tmp_name"]
以在 PHP 代码中找到上传文件的临时文件夹时,它找不到具有 upload1 名称的输入。
如何在 PHP 代码中找到输入的姓名?
尝试使用以下代码获取 $_FIELS
中的值
$("#button1").on('click', function() {
var filename = document.getElementById('image id here').value.replace(/C:\fakepath\/i, '');
var image = document.getElementById('image id here').files[0];
Data = new FormData();
Data.append('upload1', image);
Data.append('file_name', filename); //pass file name
var xmlReq = new XMLHttpRequest(); //creating xml request
xmlReq.open("POST", 'enter your url', true); //send request
xmlReq.onload = function(answer) {
if (xmlReq.status == 200) {
var response = jQuery.parseJSON(xmlReq.responseText);
console.log(response);
} else {
console.log("Error " + xmlReq.status + " occurred uploading your file.<br \/>");
}
};
xmlReq.send(Data); //send form data
});
我在 jQuery 中使用 $.ajax
从数据库中获取一些输入,当用户单击按钮时它会出现:
HTML
<div id="div1"></div>
<input type="button" id="button1"/>
JQuery
$("#button1").click(function() {
$.ajax({
type: 'POST',
url: "get.php",
data: {vals: "send"},
success : function(response) {
$("#div1").append(response);
}});
})
将元素导入到div后,将有一个input type="file"
像这样:
编辑: 我的表单代码在这里:
HTML
<input name="upload1" id="upload1" type="file"/>
<input type="button" value="submit" id="button2"/>
JQuery
$("#button2").click(function() {
$.ajax({
type: 'POST',
url: "uploadPhoto.php",
data: {filename: filename},
success : function(response) {
alert(response);
}
});
})
PHP
$filename = $_POST['filename '];
$target_dir = "image/";
$target_file = $target_dir . $filename;
var $src_temp = $_FILES["upload1"]["tmp_name"];
if (move_uploaded_file($src_temp, $target_file)) {
echo 'success';
}
结束编辑 1
当我想为这个按钮获取 $_FILES["upload1"]["tmp_name"]
以在 PHP 代码中找到上传文件的临时文件夹时,它找不到具有 upload1 名称的输入。
如何在 PHP 代码中找到输入的姓名?
尝试使用以下代码获取 $_FIELS
中的值$("#button1").on('click', function() {
var filename = document.getElementById('image id here').value.replace(/C:\fakepath\/i, '');
var image = document.getElementById('image id here').files[0];
Data = new FormData();
Data.append('upload1', image);
Data.append('file_name', filename); //pass file name
var xmlReq = new XMLHttpRequest(); //creating xml request
xmlReq.open("POST", 'enter your url', true); //send request
xmlReq.onload = function(answer) {
if (xmlReq.status == 200) {
var response = jQuery.parseJSON(xmlReq.responseText);
console.log(response);
} else {
console.log("Error " + xmlReq.status + " occurred uploading your file.<br \/>");
}
};
xmlReq.send(Data); //send form data
});