如何使用PHP从另一台服务器复制文件?

17 浏览
0 Comments

如何使用PHP从另一台服务器复制文件?

帮我解决这个问题。

我已经像这样编写了我的代码:

function copy(){
    $folder     = "PDF";
    $file       = "2016-01-001_01-00.pdf";
    $files      = "ftp://10.242.42.154/adk_rkakl2016s"." ".substr($file,8,3)."/".substr($file,12,2)."/".$folder."/"."2016-01-001_01-00.pdf";
    $newfile    = 'files/backup_file/2017-01-001_01-00.pdf';
   if (!copy($files, $newfile)) {
      echo "无法复制 $files...\n";
        } else {
      echo "成功复制 $file 到 $newfile\n";
        }
} 

我想从另一台服务器复制文件,但结果如下:

严重性: 警告 消息: copy(): connect() 失败: 连接被拒绝  文件名: controllers/Download_adk.php 行号: 146

请帮帮我。

0
0 Comments

PDF in browser. It could be due to server configuration or permissions.

One possible solution is to use the PHP function "copy" to copy the file from the remote server to your local server. Here is an example code snippet:

$fileUrl = 'http://example.com/path/to/file.pdf'; // Replace with the actual file URL
$localFilePath = '/path/to/local/file.pdf'; // Replace with the desired local file path
if (copy($fileUrl, $localFilePath)) {
    echo 'File copied successfully.';
} else {
    echo 'File copy failed.';
}

This code will attempt to copy the file from the remote server to the specified local file path. If the copy operation is successful, it will display "File copied successfully." Otherwise, it will display "File copy failed."

Please make sure that you have the necessary permissions to access the remote server and that the file you are trying to copy is accessible. Additionally, check that the file paths and URLs are correct in your code.

If the issue persists, you may need to consult with the server administrator or troubleshoot further to determine the exact cause of the problem.

0