【发布时间】:2019-08-12 12:36:10
【问题描述】:
我正在尝试调用一个函数并将结果传递到 PHP 中的 json 对象中。除功能部分外,一切正常。我在字符 1 处不断收到输入结束错误。
这是给我带来麻烦的一行
$ImageCount = getCount($fullName);
$response["count"] = $ImageCount;
这是完整的文件:
<?php
$response = array();
include 'db/db_connect.php';
include 'functions.php';
$inputJSON = file_get_contents('php://input');
//Get the input request parameters
$input = json_decode($inputJSON, TRUE); //convert JSON into array
//Check for Mandatory parameters
if(isset($input['username']) && isset($input['password'])){
$username = $input['username'];
$password = $input['password'];
$query = "SELECT full_name,password_hash, salt FROM member WHERE username = ?";
if($stmt = $con->prepare($query)){
$stmt->bind_param("s",$username);
$stmt->execute();
$stmt->bind_result($fullName,$passwordHashDB,$salt);
if($stmt->fetch()){
//Validate the password
if(password_verify(concatPasswordWithSalt($password,$salt),$passwordHashDB)){
$ImageCount = getCount($fullName);
$response["status"] = 0;
$response["message"] = "Login successful";
$response["full_name"] = $fullName;
$response["count"] = $ImageCount;
}else{
$response["status"] = 1;
$response["message"] = "Invalid username and password combination";
}
}else{
$response["status"] = 1;
$response["message"] = "Invalid username and password combination";
}
$stmt->close();
}
}else{
$response["status"] = 2;
$response["message"] = "Missing mandatory parameters";
}
//Display the JSON response
echo json_encode($response);
?>
我的 getCount() 函数代码:
function getCount($fname){
global $count;
$path = 'MobileApp/Images/';
$slash = '/';
$fullpath = $path.$fname.$slash;
//echo $fullpath;
$fi = new FilesystemIterator($fullpath, FilesystemIterator::SKIP_DOTS);
$count = (iterator_count($fi));
return $count;
}
【问题讨论】:
-
你是在php端还是android端出错?
-
@Exception PHP 端。如果我删除麻烦的代码行,一切都会完美。但是一旦我添加它。我收到错误(错误作为“结果”传递给 android,我在 logcat 上显示)。
-
你在说什么麻烦线?
-
@B001ᛦ 我没看到。我在使用 wifi 或移动数据时没有问题。另外我的问题是使用该函数获取值并将其以 JSON 传递。我的 JSON 工作正常。因为我可以在 $count 中传递我想要的任何值。但是,当我调用函数 getCount() 时,我得到了错误。另外我已经单独测试了这个功能,它工作正常。
-
@Exception $ImageCount = getCount($fullName);