我有一个名为html
的{{1}}函数的ajax
页,用于将数据发送到upload(name)
文件(upload-ad-image-inc.php)图片上传过程。
我已经尝试过使用PHP
将数据传递到相关的ajax
文件(upload-ad-image-inc.php)。
然后我使用PHP
获取了传递的数据,并将其分配给一个变量,到目前为止效果很好。数据已传递,但它是POST
这是我的Ajax功能:
missing after that.
这是我的 function upload(name) {
$(document).ready(function () {
$.ajax({
url: 'includes/upload-ad-image-inc.php',
type: 'POST',
dataType: "json",
success: function (data) {
alert(data);
},
data: {
file: name
}
}).done(function (data) {
alert(JSON.stringify(data));
});
});
}
upload-ad-image-inc.php
在这一部分中,我得到文件 $ind = filter_input(INPUT_POST, 'file');
echo $ind; //it shows file name successfully
$adId = $_SESSION['adid'];
$userId = $_SESSION['userid'];
//after this the value of $ind is missing, cannot apply to any of above.
//They show empty outputs
$file = $_FILES[$ind];
$fileName = $_FILES[$ind]['name'];
$fileTempName = $_FILES[$ind]['tmp_name'];
$fileSize = $_FILES[$ind]['size'];
$fileError = $_FILES[$ind]['error'];
$fileType = $_FILES[$ind]['type'];
echo $fileName; //this is where my problem. It doesn't show file name
的属性值
name
但是在下面,我什么都没得到, $ind = filter_input(INPUT_POST, 'file');
echo $ind; //it shows file name successfully
值
empty
这是我的“ HTML”
$file = $_FILES[$ind];
$fileName = $_FILES[$ind]['name'];
$fileTempName = $_FILES[$ind]['tmp_name'];
$fileSize = $_FILES[$ind]['size'];
$fileError = $_FILES[$ind]['error'];
$fileType = $_FILES[$ind]['type'];
echo $fileName; //this is where my problem. It doesn't show file name