2

I'm trying to read and write a file in a remote server but I can only check if it exists:

<?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;
}

?>

this is the error log:

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) }

when I try to do the same with a local path it works

I'm using WinSCP

Igor Avila
  • 21
  • 2
  • 1
    What have you done to troubleshoot `failed to open stream: Permission denied`? Here's a good checklist for starters: [PHP fopen always fails with permission denied](https://serverfault.com/questions/293143/php-fopen-always-fails-with-permission-denied) – Markus AO Oct 09 '20 at 17:10
  • you need to add chown chmod permissions to the the account your are using on your current server but on your file on the remote server – izzymo Oct 09 '20 at 18:12
  • You may need to change the mount parameters on the *nix side of things. Take a look at the umask=0022, uid=1000 and gid=1000 mount options. These can be set via the cli or in the fstab file. – Alex Barker Oct 09 '20 at 18:30
  • Does this answer your question? [Read a remote file in php](https://stackoverflow.com/questions/31572189/read-a-remote-file-in-php) – Goddard Oct 09 '20 at 21:27

0 Answers0