Search code examples
phpuploaddrive

PHP upload/read files on separate drive


I need to be able to upload/view files on a separate drive.

Right now, my site is in the htdocs folder on the C: drive. We have been allocated space on the D: drive to upload and view files.

Using the code below, I can use scandir to view what is located in htdocs folder:

<?php
 $dir    = '../../htdocs/';
 $files1 = scandir($dir);
 $files2 = scandir($dir, 1);

 print_r($files1);
 print_r($files2);
?>

But I need to traverse back a few more to be able to get to the D: drive. I am not sure if this is even possible.

Using the above code, when I attempt to traverse to the D: drive, the path would look something like this:

$dir    = '../../../D:/uploadFiles/';

I am not sure if that is the correct format when going back and viewing something in the D: drive. I guess if it was, I would be seeing something on the screen, which I am not.

Upon conducting my research online, the closest thing that I could find was this post:

upload file on drive d:// php

But I need to be able to first read the files in the folder on the D: drive.

Is what I am trying to do possible using PHP? If it is, how can I fix my path so that I can see the files in the uploadFiles folder on the D: drive?


Solution

  • All Directory Functions.

    Simple as:

    scandir('C:/some/path/uploadFiles');
    scandir('D:/some/path/www/htdocs');
    

    Or whatever... Write out the full paths. Don't even do that ../../ stuff. Relative paths / absolute paths. I think you are overcomplicating things.