我有一台运行在客户端计算机上的Apache服务器,安装了PHP。我已经安排了一个任务来自动创建数据库备份,它工作正常。但是把备份保存在系统运行的同一个高清上是没有意义的,所以我必须把它发送到别的地方。
起初,我尝试做一个PHP FTP上传,但客户端的防火墙阻止了所有的FTP连接,我不能解除阻止(他的公司不会允许我)。 然后,我尝试使用SMTP发送备份,到一个电子邮件帐户。也没有工作。所有的SMTP连接也被阻止(我知道...)。
我正在尝试通过HTTP POST REQUEST访问网页(在我的服务器上)附加在页眉上的文件。它应该是可能的,看到这几乎是浏览器,与文件输入对象,对不对?我只是使用页眉来发送multipart / data。
我需要手动创建页眉吗?或者是否有任何脚本已经这样做? / curl> curl 通过http发送。假设你的文件是'/tmp/backup.tar.gz',它应该是: $ p $ code $ curl_init(' clientserver/upload.php'); $ ch = curl_setopt($ ch,CURLOPT_POST,true); $ ch = curl_setopt($ ch,CURLOPT_POSTFIELDS,array('file'=>'@ / tmp / backup.tar.gz')); $ ch = curl_setopt($ ch,CURLOPT_USERPWD,'username:password'); $ result = curl_exec($ ch); if($ result === FALSE){ die(curl_error($ ch)); }
这就是基础。你可能需要更强大一些。假设接收服务器上的上传脚本是在php中完成的,您可以像 $ _ FILES ['file'] 那样访问该文件。
I have an Apache server running on a client's computer, with PHP installed. I have scheduled a task to automatically create a database backup, and it's working fine. But it makes no sense keeping the backups on the same HD the system's running, so I have to send it somewhere else.
At first, I tried doing a PHP FTP Upload, but the client's firewall's blocking all FTP connections, and I cannot unblock it (his company won't allow me).
Then, I tried sending the backup using SMTP, to an e-mail account. Also didn't work. All SMTP connections are also blocked (I know...).
I'm trying now to access a webpage (on my server), via a HTTP POST REQUEST, with the file attached on the page-header. It should be possible, seeing that's pretty much what the browser does, with a file-input object, right? I just sends the multipart/data using the page header.
Will I have to create the page header manually? Or are there any scripts that already do that?
解决方案You can use curl to send it via http. Assuming your file is '/tmp/backup.tar.gz', it'd be:
$ch = curl_init('clientserver/upload.php'); $ch = curl_setopt($ch, CURLOPT_POST, true); $ch = curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@/tmp/backup.tar.gz')); $ch = curl_setopt($ch, CURLOPT_USERPWD, 'username:password'); $result = curl_exec($ch); if ($result === FALSE) { die(curl_error($ch)); }That's the basics. you'd probably need to make it a bit more robust. Assuming the upload script on the receiving server is done in php, you'd access the file as $_FILES['file'].
更多推荐
将文件从一台服务器上传到另一台服务器(通过HTTP POST)
发布评论