0

So I'm using TCPDF to generate a pdf file and trying save the generated document on a folder residing on another server using

$pdf->Output('\\\210.24.39.6\salesorder\salesorder.pdf', 'F');

And I got the error

Warning: fopen(): remote host file access not supported,

I am able to access the path and folder remotely from the server machine. Does anyone know why?

Smern
  • 18,746
  • 21
  • 72
  • 90
user3543512
  • 133
  • 1
  • 1
  • 13

3 Answers3

1

You can mount share as a drive on Windows or to a folder on linux servers, than you will work with it like a local file system.

For windows:

net use \\210.24.39.6\salesorder\

For linux (don't forget to create folder salesorder):

mount –t cifs 210.24.39.6:/salesorder /fullpath/salesorder –o username=test,workgroup=test
vanadium23
  • 3,516
  • 15
  • 27
0
  1. One possible solution is scp, which stand for Secured Copy.

    It's syntax is the following:

    scp /local/dir/file.pdf root@destination.net:target/dir/file.pdf
    

    It copies file over SSH and requires SSH key to be authorized on destination server to omit password request.

  2. Another solution is to copy file using FTP protocol.

  3. Or set allow_url_fopen = 1, but than read abouth the risks of doing that here and here. Shortly: it is not secured.

! Options 1 and 2 require that file is generated/saved on source location and that copied to another/target location.

Community
  • 1
  • 1
Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
0

Another option besides scp (which is a good option) is to generate the PDF locally, then copy it to the IP or UNC name. an implementation I used is below:

1) generate the pdf to your local drive. (wherever that is for you)

$pdf->Output($filename, 'F');

2) use the built in php function to copy that file to your remote drive. I built a function to do that as I wanted to also do some checking, to make sure it could proceed without error.

function CheckDirectoryExists($path) {
    if (!file_exists($path)) {          
        mkdir($path, 0777, true); 
    }
    return file_exists($path);
}

function CopyFile($file, $to_file) {
    if (!file_exists($file)) {
        return -1;
    }
    if (!file_exists($to_file)) {
        $path = '';
        $explodedPath = explode(dirSep, $to_file);
        for ($i = 0; $i < (sizeof($explodedPath) - 1); $i++) {
            $path .= $explodedPath[$i] . dirSep;
        }
        CheckDirectoryExists($path);
    } else {
        unlink($to_file);
    }
    return copy($file, $to_file);
}

this should work, I'm using the UNC name instead of the IP address on my end in the init.php I have setup.

Morris Buel
  • 126
  • 1
  • 8