在远程服务器PHP中读取文件

在远程服务器PHP中读取文件,php,winscp,Php,Winscp,我正在尝试在远程服务器中读取和写入文件,但我只能检查它是否存在: <?php echo 'test'; set_include_path('/mnt/vpn'); $dst = "/mnt/vpn"; echo $dst, file_exists($dst) ? ' exists' : ' does not exist', "<br><br>"; echo $dst, is_readable($dst) ? '

我正在尝试在远程服务器中读取和写入文件,但我只能检查它是否存在:

<?php
echo 'test';
 set_include_path('/mnt/vpn');

    $dst = "/mnt/vpn";

echo $dst, file_exists($dst) ? ' exists' : ' does not exist', "<br><br>";
echo $dst, is_readable($dst) ? ' is readable' : ' is NOT readable', "<br><br>";
echo $dst, is_writable($dst) ? ' is writable' : ' is NOT writable', "<br><br>";

$fh = fopen($dst, 'r',1);

if ( !$fh ) {
    echo ' last error: ';
    var_dump(error_get_last());
} else {
 echo $fh;
}

?>
当我尝试对本地路径执行同样的操作时,它会起作用


我正在使用WinSCP

您做了什么来排除打开流失败的故障:权限被拒绝?这里有一个很好的清单供初学者使用:您需要向当前服务器上使用的帐户添加chown chmod权限,但在远程服务器上的文件上,您可能需要更改*nix端的装载参数。看看umask=0022、uid=1000和gid=1000装载选项。可以通过cli或在fstab文件中设置。这是否回答了您的问题?
test/mnt/vpn exists

/mnt/vpn is NOT readable

/mnt/vpn is NOT writable


Warning: fopen(/mnt/vpn): failed to open stream: Permission denied in /var/www/html/test.php on line 11
last error: array(4) { ["type"]=> int(2) ["message"]=> string(57) "fopen(/mnt/vpn): failed to open stream: Permission denied" ["file"]=> string(22) "/var/www/html/test.php" ["line"]=> int(11) }