2015-09-07 134 views
0

我想將圖像存儲到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

回答

1

添加enctype="multipart/form-data">到窗體tag.This需要的值,當您使用的是有一個文件上傳控件

形式這將是

<form class="form-horizontal signUPForm" method="post" action="most_wanted_ajax.php" `enctype="multipart/form-data"`> 
+0

非常感謝,先生它的工作..... :) –

+0

@RajeevSrivastava歡迎你。 – Saty

+0

亞肯定先生..... :) –