我正在寻找一个脚本,您可以从一台服务器自动下载文件,并使用php和cron作业上传到数据库。有人能指出我正确的方向吗?
感谢。
答案 0 :(得分: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);
我希望它有所帮助