这是我的web服务,是从android到php服务器的图片上传。我在Advance Rest Client中运行此服务,但每次都会发生未定义的索引错误。
这是我的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.";
}
?>
答案 0 :(得分:0)
您不能对if值使用if条件。这意味着
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'];}