php - Using DirectoryIterator to loop through a D: drive directory -
i trying loop through directory:
$path = "d:\\import\\statsummary\\";
here code:
$path = "d:\\import\\statsummary\\"; //$path = "c:\\test"; //function load_csv($path, $filename){ if(is_null($filename)){ header('content-type: text/plain'); $output = array(); foreach (new directoryiterator($path) $file){ if($file->isfile()){ $output[] = $i++ . " " . $file->getfilename() . "\n"; $output[] = file($file->getpathname()); $output[] = "\n------------\n"; } } } echo implode('', $output);
when run script, error:
fatal error: uncaught exception 'unexpectedvalueexception' message 'directoryiterator::__construct(d:\import\statsummary\,d:\import\statsummary\): access denied. (code: 5)' in c:\inetpub\wwwroot\include\file_importer.php:10 stack trace: #0 c:\inetpub\wwwroot\include\file_importer.php(10): directoryiterator->__construct('d:\import\...') #1 {main} thrown in c:\inetpub\wwwroot\include\file_importer.php on line 10
but when change test directory on c:\
drive, runs fine. i've created username run php directed in post:
based on directoryiterator class, should work:
<?php $path = "d:/import/statsummary"; $output=array(); $iterator = new directoryiterator(path); foreach ($iterator $fileinfo) { if ($fileinfo->isfile()) { $filename= $fileinfo->getfilename(); $path=$fileinfo->getpathname(); $output[][$filename]=$path; } } print_r($output); ?>
update
since you're getting access denied, you'll need run command prompt
(cmd) window administrator more likely. if on link
(lnk) can change permissions in link settings.
for instance if right-click on shortcut cmd select properties
, go shortcut>advanced>run administrator.
Comments
Post a Comment