I am able to save the results as JSON. The problem I am having is saving it to a network drive.
I confirmed the path is good by using the following:
if ($handle = opendir('//network/IS/folder1/folder2/targetdirectory'))
{
echo "Directory handle: $handle\n";
echo "Entries:\n";
// This is the correct way to loop over the directory.
while (false !== ($entry = readdir($handle))) {
echo "$entry\n";
}
// This is the WRONG way to loop over the directory.
while ($entry = readdir($handle)) {
echo "$entry\n";
}
closedir($handle);
}
Using the above, I am able to see all of the files in the targetdirectory. Therefore, I know the path is good. It's writing/creating the text file that is to be saved in the targetdirectory.
The whole process looks like this:
<?php
include("../include/sessions.php");
if(isset($_POST['selectedOption']))
{
$svc1 = mysqli_real_escape_string($dbc, $_POST['selectedOption']);
$sql = "SELECT column1, column2, column3 FROM table WHERE column1 = '$svc1'";
$query = mysqli_query($dbc, $sql);
if($query)
{
$out = array();
while($row = $query->fetch_assoc())
{
$out[] = $row;
}
$json = json_encode($out); // I can change $json to echo and see the $out in the console as json
$file = fopen(__DIR__ . "//network/IS/folder1/folder2/targetdirectory", 'w');
fwrite($file, $json);
fclose($file);
}
else
{
echo "Error: " . mysqli_error($dbc);
}
?>
Using the above process, nothing is being saved into the targetdirectory.
What I can do to fix this problem?