Passing an instance of DirectoryIterator to another script via exec () does not work properly

I have a page that executes a script for each file in a directory:

$dir = new DirectoryIterator('/var/www/OCR3/upload_pending/');

foreach ($dir as $fileinfo) {
    exec("php manual_doc_proccessor.php $fileinfo");
    echo "php manual_doc_proccessor.php $fileinfo" . " Sent for proccessing <BR>";
}

Going to this script:

$fileinfo = $argv[1];
if (!$fileinfo->isDot()) {
    print_r($fileinfo->getFilename()) . PHP_EOL ;
    $fileName = $fileinfo->getFilename();
    echo $fileName;
}

However, when the script is executed, I get an error:

Calling a member function isDot () for a non-object

I expect that each iteration of the script will be an echo of the file name, but instead I will get an error.

What am I missing and how can I get this to process files correctly?

+4
source share
1 answer

$fileinfo script, DirectoryIterator, __toString(), . isDot() getFilename(), if :

$fileinfo = $argv[1];
if ($fileinfo != "." && $fileinfo != "..") {
    print_r($fileinfo) . PHP_EOL ;
    $fileName = $fileinfo;
    echo $fileName;
}
+2

All Articles