Php 文件内容(result.json):无法打开流:权限被拒绝
我试图用PHP生成一个.JSON文件,供Android使用。我得到以下错误: 文件\u put\u contentsresult.json:无法打开流:第18行的权限被拒绝 这是我的密码:Php 文件内容(result.json):无法打开流:权限被拒绝,php,json,Php,Json,我试图用PHP生成一个.JSON文件,供Android使用。我得到以下错误: 文件\u put\u contentsresult.json:无法打开流:第18行的权限被拒绝 这是我的密码: <?php require 'conn.php'; $name = array();//array created to store the data. $sql="SELECT * FROM employee_data;"; $result = mysqli_query($conn,$sql) or
<?php
require 'conn.php';
$name = array();//array created to store the data.
$sql="SELECT * FROM employee_data;";
$result = mysqli_query($conn,$sql) or die ("Error in query: $query. ".mysql_error());
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$output[] = $row;
}
}
$jsonarray = json_encode(array('output'=>$output));
echo $jsonarray;
//Take special care of the msqli and the sql queries
//creates the file
$fileName = 'result'.'.json';
if (file_put_contents($fileName, $jsonarray)) {
echo $jsonarray." is created";
}else{
echo "There is some error";
}
?>
感谢您的帮助:
<?php
require 'conn.php';
$name = array();//array created to store the data.
$sql="SELECT * FROM employee_data;";
$result = mysqli_query($conn,$sql) or die ("Error in query: $query. ".mysql_error());
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$output[] = $row;
}
}
$jsonarray = json_encode(array('output'=>$output));
echo $jsonarray;
//Take special care of the msqli and the sql queries
//creates the file
$fileName = 'result.json';
if (file_put_contents($fileName, $jsonarray)) {
echo $jsonarray." is created";
}else{
echo "There is some error";
}
?>
问题在您的$fileName中。
请检查以上代码。
我希望这会有所帮助。不确定我们还能在错误消息中添加什么-无论哪个系统用户运行PHP脚本www data,etc都没有将该文件写入工作目录的权限与android标记无关我相信这个问题与android无关。删除android标记您正试图在您没有权限在其中写入的文件夹中写入…您的帖子在错误的标记中