First please excuse any grammar or spelling mistakes. English is my second language and it's 2AM at the time of writing this. I was trying to create a php script that can be executed in powershell, which from inside a hyper-v virtual machine. This script would take files from a drive which is shared with the virtual machine and hashes these files.
I followed this guide for accessing the shared drive. This guide for executing php scripts in powershell. For that you need to set these environment variables.
The below code is what I am trying to execute and it is located at: \\tsclient\E\My_Projects\new_code\hashing_script.php
$directory = "\\tsclient\E\My_Projects\new_data";
$directoryContents = scandir("$directory");
$counter = count($directoryContents, 0);
$hashes = [0, 0];
for($i = 2; $i < $counter; $i++)
{
$hash = hash_file("sha512", "$directory\$directoryContents[$i]");
array_push($hashes, $hash);
}
var_dump($hashes);
when I execute the code in powershell with the command: php.exe \\tsclient\E\My_Projects\new_code\hashing_script.php
I get the following error message:
PHP Warning: scandir(\tsclient\E\My_Projects
ew_data, \tsclient\E\My_Projects
ew_data): Das System kann den angegebenen Pfad nicht finden. (code: 3) in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
Warning: scandir(\tsclient\E\My_Projects
ew_data, \tsclient\E\My_Projects
ew_data): Das System kann den angegebenen Pfad nicht finden. (code: 3) in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
PHP Warning: scandir(\tsclient\E\My_Projects
ew_data): failed to open dir: No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
Warning: scandir(\tsclient\E\My_Projects
ew_data): failed to open dir: No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
PHP Warning: scandir(): (errno 2): No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
Warning: scandir(): (errno 2): No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
PHP Warning: count(): Parameter must be an array or an object that implements Countable in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 3
Warning: count(): Parameter must be an array or an object that implements Countable in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 3
array(2) {
[0]=>
int(0)
[1]=>
int(0)
}
Das System kann den angegebenen Pfad nicht finden
is german and roughly translates to:
The system can not find the path specified
The two main things that I have noticed about the error messages are that:
- when it returns the address path one of the backslashes is missing
- it interperates the folder name as \new_code as \n and continues on the next line.
To fix this I have:
- run other test files that just echo data and they work excelently.
- tried reading the dir name from a .txt file. This returned an error message that it was unable to find the .txt file.
- tried using $_SERVER['DOCUMENT_ROOT'] this did not change a lot in the error message.
I have come to the conclusion that it almost seems that powershell/php thinks that \tsclient\E\My_Projects\new_code\hashing_script.php is a directory and is trying to search inside of it, which obviously won't work.
Thank you for taking your time to read this any and all suggestions/ideas/questions are welcome.