0

I want to set a directory path but my folder on desktop so in case if i host a my app how it will take automaticaly that path here is my code

$src = 'C:\Users\Nikhil.Chakor\Desktop/test/';  
$test = Get_ImagesToFolder1($src);

function Get_ImagesToFolder1($src){
    $ImagesArray = [];
    $file_display = [ 'jpg', 'jpeg'];
    if (file_exists($src) == false) {
        return ["Directory \'', $src, '\' not found!"];
    } else {
        $dir_contents = scandir($src);
        foreach ($dir_contents as $file) {
            $file_type = pathinfo($file, PATHINFO_EXTENSION);
            if (in_array($file_type, $file_display) == true) {
                $ImagesArray[] = $file;
            }
        }
        return $ImagesArray;
    }
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
CE cenveo
  • 1
  • 2
  • Does this answer your question? [PHP Get name of current directory](https://stackoverflow.com/questions/9997391/php-get-name-of-current-directory) – ikyuchukov Sep 27 '22 at 10:38
  • Good code indentation would help us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](https://www.php-fig.org/psr/psr-12/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Sep 27 '22 at 10:39
  • 3
    This doesn't really make much sense. A typical server-side PHP program will run either as a dedicated user or as the web server user. Those users won't have desktops set up and the system could have zero to many different users who do have desktops set up. Are you assuming that the system will have exactly one user with a desktop folder? Are you assuming that the system will be running Microsoft Windows? – Quentin Sep 27 '22 at 10:40
  • Are you running this from the CLI or via a web server? – RiggsFolly Sep 27 '22 at 10:41
  • see i have one directory on desktop which is test so i have to set a path in code like how set in $src but its working on only my desktop in future if i hosted my app i want to work that on all desktop – CE cenveo Sep 27 '22 at 10:45
  • no i am not running from cli im using xampp server to run my code on webpage – CE cenveo Sep 27 '22 at 10:46
  • 1
    Then you should not be able to access that folder anyway, unless thats where your Document Root is. Remember, most hosting sites are Linux based and they will not understand `C:\\` let alone the rest of that path – RiggsFolly Sep 27 '22 at 10:52

0 Answers0