In a .php page I have the function below. In localhost the JSON response is different than NULL, but when I put the page in on the server (FTP) the JSON response is NULL.
THE CODE
// Check for required parameters
if (isset($_POST["placetype"]) && isset($_POST["placeName"])) {
$pt = $_POST["placetype"];
$pn = $_POST["placeName"];
$dir = 'Pictures/Attractions/'.$pt.'/'.$pn.'/';
$files = scandir($dir);
foreach($files as $ind_file) {
$result[] = array(
"data" => $ind_file
);
sendResponse(200, json_encode($result));
return true;
}//ifisset
sendResponse(400, 'Invalid request');
return false;
Note: the same folders are on both local and on the server.
Thanks.
See this
$files = scandir($dir);
If you haven't files in $dir, you variable $result will not create and will hold nothing, json will return null. On remote server you haven't files and json_encode return null
I'm guessing the PHP install on your server is not up to date. json_encode()
only works with PHP 5 >= 5.2.0.