addcategory.php
<div class=col-md-12>
<div class="form-group">
<label for="image">Background Image</label>
<input type="file" id="uploadedimage" name="uploadedimage"
placeholder="Background Image" class="file" data-preview-file-type="text">
</div></div>
<div class=col-md-2><div class="form-group">
<button class="btn btn-large btn-primary" name="add" id="add" type="button"
onclick="newsubject();">Add</button>
</div></div>
**subject.js**
function newsubject()
{
var xmlhttp;
var subject=document.frmsubject.subject.value;
var uploadedimage=document.getElementById("uploadedimage").files[0].name;
var x="frm=nsubject&subject="+subject+"&uploadedimage="+uploadedimage;
xmlhttp.open("GET","ajax/newsubject.php?"+x,true);
xmlhttp.send();
}
**newsubject.php**
function nsubject()
{
$sub=$_GET['subject'];
$img=$_GET['uploadedimage'];
echo $img;
if(!empty($_FILES[$img]["name"]))
{
echo "hello";
$file_name=$_FILES[$img]["name"];
$temp_name=$_FILES[$img]["tmp_name"];
$imgtype=$_FILES[$img]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "adminImage/".$imagename;
if(move_uploaded_file($temp_name, $target_path))
{
$query_upload="INSERT into tblcategory(categname,bimage)
VALUES('$sub','$target_path')";
$res=mysql_query($query_upload);
}
}
点击按钮,将从js文件中调用newsubject。主题名称和img将被传递给newsubject.php文件,然后图像将被上传。但是这样做会让$ _FILES [$ img] [&#34; name&#34;]为空。请帮忙。