0

我需要制作一个 PHP 函数来在两台服务器之间移动文件...例如,我有 Sever1 和 Server2,我在 Server1 上有一个 file1.php,我需要执行一个 PHP 函数,例如:server1/execute.php将 file1.php 移动到 Server2 上的特定目录。

我在用着:

<?php
$filename="file1.php";
unlink("ftp://USER:PASSWORD@IPADDRESS/httpdocs/DESTINATIONFOLDER/".$filename);
if(!copy($filename, "ftp://USER:PASSWORD@IPADDRESS/httpdocs/DESTINATIONFOLDER/".$filename))  
{echo "error";}

?>    

该代码在我的本地服务器上工作,但是当我在服务器上发布时,文件复制不完整。

有什么想法?

4

3 回答 3

0

If the file is too large and cannot be copied in the time allocated to a script, the copy will be interrupted.

Use set_time_limit(0); to remove the time limit. Be aware that you cannot do this on all server configurations.

Another measure to take, is checking the file size at the end of the transfer, like this you can handle the case when an error occurs and the upload is only partial.

于 2013-10-09T16:04:50.557 回答
0

我认为你必须打开 php.ini 中的 allow_url_fopen 并将 755 权限设置为源文件。并且您必须有权访问目标文件夹。

或使用类似的东西:http ://stephenmcintyre.net/blog/copy-images-allow_url_fopen-off

于 2013-10-10T11:18:40.550 回答
0

好吧,您可以使用 ftp 传输文件。使用以下简单易行的代码来执行此操作。

/**
* Transfer (Export) Files Server to Server using PHP FTP
*/

/* Remote File Name and Path */
$remote_file = 'files.zip';

/* FTP Account (Remote Server) */
$ftp_host = 'your-ftp-host.com'; /* host */
$ftp_user_name = 'ftp-username@your-ftp-host.com'; /* username */
$ftp_user_pass = 'ftppassword'; /* password */


/* File and path to send to remote FTP server */
$local_file = 'files.zip';

/* Connect using basic FTP */
$connect_it = ftp_connect( $ftp_host );

/* Login to FTP */
$login_result = ftp_login( $connect_it, $ftp_user_name, $ftp_user_pass );

/* Send $local_file to FTP */
if ( ftp_put( $connect_it, $remote_file, $local_file, FTP_BINARY ) ) {
echo "WOOT! Successfully transfer $local_file\n";
}
else {
echo "Doh! There was a problem\n";
}

/* Close the connection */
ftp_close( $connect_it );
于 2017-03-29T08:49:59.400 回答