$ _FILE textfield name index is not recognized
问题描述:
我想将图像存储到mysql数据库中,但在ajax页面$_FILE['textfield_Name']['temp_name']
不能识别它。帮我解决这个问题。
这是我的文件页面代码
<form class="form-horizontal signUPForm" method="post" action="most_wanted_ajax.php">
<label for="images">Upload Image</label>
<input type="file" name="images">
<br>
<button type="submit" id="add" value="Submit" >Add Most Wanted</button>
</form>
我jQuery代码是:
$("#add").click(function (e){
$.post($(".signUPForm").attr("action"),$(".signUPForm").serializeArray(),function(res){
if(res!=null){
alert("mosted wanted added");
}
else
{
alert("Somthing is fishy");
}
});
});
这里是我most_wanted_ajax.php代码
<?php
if(getimagesize($_FILES['images']['tmp_name'])==FALSE)
{}
else
{
$image=addslashes($_FILES['images']['tmp_name']);
$image= file_get_contents($image);
$image= base64_encode($image);
$con=mysqli_connect("localhost","root","","ecopsweb");
$insertSQL="insert into most_wanted(images) values('".$image."')";
$rs= mysqli_query($con, $insertSQL);
$id= mysqli_insert_id($con);
header("location: missing_person_info.php");
}
?>
在most_wanted_ajax.php页给出两个错误
说明:未定义指数:在 Ç图像:\瓦帕\ WWW \ eCopsWeb \ adminModule \ most_wanted_ajax.php上线3
警告:和getimagesize():文件名不能在 C是空的:\瓦帕\ WWW \ eCopsWeb \ adminModule \ most_wanted_ajax.php上线3
答
添加enctype="multipart/form-data"
>到窗体tag.This需要的值,当您使用的是有一个文件上传控件
形式这将是
<form class="form-horizontal signUPForm" method="post" action="most_wanted_ajax.php" `enctype="multipart/form-data"`>
非常感谢,先生它的工作..... :) –
@RajeevSrivastava欢迎你。 – Saty
亚肯定先生..... :) –