【发布时间】:2015-10-20 10:23:57
【问题描述】:
我在 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 代码中找到输入名称?
【问题讨论】: