Tuesday 11 June 2019

scandir - Error when running my php script

I have these errors when running my script.




failed to open dir: No such file or directory in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6



Warning: scandir(): (errno 2): No such file or directory in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6



Warning: array_diff(): Argument #1 is not an array in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6




Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 7




Well this is my code below, I don't understand why it failed to open my dir when it's being declared below? Can someone help me with this.



Code of my word2.php



$numargs = count($argv);
if ($numargs > 1) {

$folder = $argv[1];
echo "Folder is: " . $folder . "\n";
$files = array_diff(scandir($folder), array('.', '..')); //line 6
foreach ($files as $file) { //line 7
$filename = str_replace("í»", "", $filename);
}
} else {
echo "You need to pass the folder absolute path";
exit();
}



Code for running my script using this command ./run.bat this is the filename with a code below.



php word2.php "/Applications/MAMP/htdocs/sites-store/word/images"

PAUSE

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...