I have a simple PHP script in a main asp.net project. The script should copy another script with cyrillic in the path to the web server and run it using the Curl library. But the copy() or fopen() methods do not work – access is denied.
First I tried setting read access to the file using chmod():
<?php
$path = "C:\Users\Stanislav\Documents\Visual Studio Projects\ForumEngine\wwwroot\src\user-account.php";
chmode($path, 0755);
?>
But this had no effect.
Then I tried to set Acl using the appropriate powershell command, but first – get it, make change and then – set. I have run Get-Acl command, using shell_exec, but it return empty result.
<?php
$log_filename = (string)$_SERVER["DOCUMENT_ROOT"] . "\report.log";
$log_handle = fopen($log_filename, "w+");
if($log_handle !== false)
{
ini_set("syslog.filter", "all");
set_error_handler(function(int $errno, string $errstr, string $errfile = null, int $errline = 0) use($log_filename)
{
$message = "Error: {$errno} in {$errfile}, line no {$errline}n{$errstr}";
return error_log($message, 3, $log_filename);
}, E_ALL);
}
header("Content-Type: text/html; charset=Windows-1251");
$EOL = "<br>n";
echo "<pre>";
$path = "C:\Users\Станислав\Documents\Visual Studio Projects\ForumEngine\wwwroot\src\user-account.php";
echo "{$EOL}path: {$path}";
$command = "(Get-Acl '{$path}').Access | Format-List";
echo "{$EOL}command: {$command}";
$result = shell_exec('powershell -InputFormat none -ExecutionPolicy ByPass -NoProfile -Command "& {' . (string)$command . '}"');
$result = is_string($result) ? trim($result) : "error occurred";
echo "{$EOL}Get-Acl result: {$result}";
echo "</pre>";
if($log_handle !== false)
{
fclose($log_handle);
}
?>
When I tried get Acl for path, wich don’t contains cyrillic, shell_exec was return correct result.
How correctly execute powershell commands which contans cyrillic?