PHP chdir issues

70 Views Asked by At

My Directories:

  • Main: "WWW" (Here are my php scripts and subfolders)
  • "www/images" (This is where the images sent by users are stored)

My scripts are:

- Switch.php

<?php
include 'getdir.php';
switch (count($files)) {
case '1':
$fname = "database.php";
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
$content = substr_replace($content, ', '.'"'.$files[0].'"', -6, 0);
$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);
break; //dance
}
?>

In this script we use a switch to check if a file exists inside "www/images"

The file is represented in array by "$files[0]" var, which is provided by the script "getdir.php" and if a file exists, we will create a line of code inside the file "database.php" which is located in "www" (the main folder of all scripts)

And finally we can explain our next script "getdir.php"

- getdir.php

<?php 
$dir = "images"; //Our files directory;
chdir($dir);
array_multisort(array_map('filemtime', ($files = glob("*.{jpg,png}", 
GLOB_BRACE))), SORT_REGULAR, $files); //Get an array list for dynamic 
files purposes;
?>

The script "getdir.php" needs to return information for "switch.php", but it only takes the "images" directory and does not consider the directory "www"

The "switch.php" needs to store information in "database.php" located in "www" (one level below) of ("www/images").


Because 'chdir' in "getdir.php" the output's of "switch.php" and "getdir.php" are as follows:

"getdir.php" output;

Warning: chdir(): No such file or directory (errno 2) in C:\phpdesktop-chrome-57.0-rc-php-7.1.3\www\getdir.php on line 3

"switch.php" output;

  • Create a file "database.php" in "images" directory and store the information inside it.

But this is not the result that I need and I've tried to do several things, such as "//chdir" or
"$dir=[" images "," www "];" and many other things but no success.


Summary of everything:

  • I need the informations located in the directories "images" and "www" and not only the directory "images"

  • I would like to store the information obtained by "switch.php" in the file "database.php" located in "www" instead of creating a new file "database.php" in "images"

Thanks for your attention.

0

There are 0 best solutions below