2017-02-12 26 views
-1

這是我的web服務,這是從android到php服務器的圖像上傳。我在Advance Rest Client中運行此服務,但每次都會發生未定義的索引錯誤。未定義的索引,而圖像上傳在PHP

這是我的PHP文件:

<?php 
session_start(); 
include('classes/mainclass.php'); 
header('Content-type: application/json; charset=utf-8'); 
$CustomHeaders = apache_request_headers(); 

$category=array(); 

$main_cat = $_POST['main_cat']; 
$sub_cat = $_POST['sub_cat']; 
$content_name = $_POST['content_name']; 
$address=$_POST['address']; 
$contact=$_POST['contact']; 
$website=$_POST['website']; 
$email=$_POST['email']; 
$additional=$_POST['additional']; 
//$imgurl=$_POST['imageurl']; 


$dataObj = new UserClass(); 

$target_dir = "uploads/"; 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 

$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
    $imageUrl = $target_dir.basename($_FILES["fileToUpload"]["name"]); 

    $result1 = $dataObj->requestcontent($main_cat,$sub_cat,$content_name,$address,$contact,$website,$email,$additional,$imageUrl); 

      if($result1) 
      {  
       ResponseClass::ResponseMessage("1","Content Request Submitted","True"); 

      } 
      else 
      { 

       ResponseClass::ResponseMessage("2","Content Request Not Submitted","False"); 
      } 



} else { 
    echo "Sorry, there was an error uploading your file."; 
} 
?> 

Error look like this..

+0

請確保您的請求在發佈 –

+0

是您的請求內容類型json或鍵值? –

+0

請求在post @ B.Desai –

回答

0

不能使用,如果條件後的值。這意味着

if(isset($_POST){$main_cat = $_POST['main_cat'];$sub_cat = $_POST['sub_cat'];$content_name =$_POST['content_name'];$address=$_POST['address'];$contact=$_POST['contact'];$website=$_POST['website'];$email=$_POST['email'];$additional=$_POST['additional'];} 
+0

所有代碼都難以讀取,而且您不需要執行'isset($ _ POST)' - 數組本身始終可用。 – halfer