0

我正在寻找一个脚本,您可以从一台服务器自动下载文件并使用 php 和 cron 作业上传到数据库。谁能指出我正确的方向?

谢谢。

4

1 回答 1

2

您可以使用ftp和 php 该功能:http ://www.php.net/manual/en/book.ftp.php

概念证明

$remoteUrl = "http://balabla/abc.pdf" ; // to remote file
$localTemp = "temp" ; // Temp directory 
$file = 'somefile.txt';
$ftpServer = "";
$ftpUsername = "";
$ftpPassword = "" ;
$serverPath = 'data/upload/'; // this most exist on your the server you are uploading to

//Get Remote FIle 
$localFile = $localTemp . DIRECTORY_SEPARATOR . basename($remoteUrl);
file_put_contents($fileName, file_get_contents($remoteUrl));


//Upload The File 

$connID = ftp_connect($ftpServer);
$loginID = ftp_login($connID, $ftpUsername, $ftpPassword);

if(!$connID || !$loginID)
{
    die("Can't Connect to FTP");
}

ftp_chdir($connID, $serverPath); //Change Directory 

if (ftp_put($connID, $localFile, basename($localFile), FTP_BINARY )) {
    echo "successfully uploaded $localFile\n";
} else {
    echo "There was a problem while uploading $localFile\n";
}

// close the connection
ftp_close($connID);

我希望它有帮助

于 2012-04-16T09:40:14.150 回答