[英]Server to Server > Retrieve and extract a remote zip file to local server directory
I have a wp plugin file on server B who's purpose is to retrieve a zip file from a remote server A. 我在服务器B上有一个wp插件文件,其目的是从远程服务器A检索一个zip文件。
Once Server B receives the zip file, it should extract the contents and copy the files into a specific folder on server B overwriting any existing files. 一旦服务器B收到zip文件,它就应该提取内容并将文件复制到服务器B上的特定文件夹中,覆盖任何现有文件。
I have some code below that I've borrowed from a file that uses and uploader to do the same thing and I'd just like to redo it for the automated server to server procedure described above. 我在下面有一些代码,我从一个使用和上传器的文件中借用了同样的东西,我只想重做上面描述的自动服务器到服务器程序。 But I'm getting a fatal error when trying to Activate this plugin.
但是在尝试激活此插件时,我遇到了致命的错误。
function remote_init()
{
openZip('http://myserver.com/upgrade.zip');
$target = ABSPATH.'wp-content/themes/mytheme/';
}
function openZip($file_to_open, $debug = false) {
global $target;
$file = realpath('/tmp/'.md5($file_to_open).'.zip');
//$file is always empty. // $ file始终为空。 can't use realpath in this case.
在这种情况下不能使用realpath。 What to do?
该怎么办?
$client = curl_init($file_to_open);
curl_setopt(CURLOPT_RETURNTRANSFER, 1);
$fileData = curl_exec($client);
file_put_contents($file, $fileData);
$zip = new ZipArchive();
$x = $zip->open($file);
if($x === true) {
$zip->extractTo($target);
$zip->close();
unlink($file);
} else {
if($debug !== true) {
unlink($file);
}
die("There was a problem. Please try again!");
}
}
add_action( 'init','remote_init');
I did a quick check in the manual, and there was a slight error on line 5. 我在手册中做了快速检查,第5行出现了轻微错误。
$target = ABSPATH .'wp-content/themes/mytheme/';
function openZip($file_to_open, $debug = false) {
global $target;
$file = ABSPATH . '/tmp/'.md5($file_to_open).'.zip';
$client = curl_init($file_to_open);
curl_setopt($client, CURLOPT_RETURNTRANSFER, 1); //fixed this line
$fileData = curl_exec($client);
file_put_contents($file, $fileData);
$zip = new ZipArchive();
$x = $zip->open($file);
if($x === true) {
$zip->extractTo($target);
$zip->close();
unlink($file);
} else {
if($debug !== true) {
unlink($file);
}
die("There was a problem. Please try again!");
}
}
function openZip($file_to_open, $debug = false) {
global $target;
$file = realpath('/tmp/'.md5($file_to_open).'.zip');
$client = curl_init($file_to_open);
curl_setopt(CURLOPT_RETURNTRANSFER, 1);
$fileData = curl_exec($client);
file_put_contents($file, $fileData);
$zip = new ZipArchive();
$x = $zip->open($file);
if($x === true) {
$zip->extractTo($target);
$zip->close();
unlink($file);
} else {
if($debug !== true) {
unlink($file);
}
die("There was a problem. Please try again!");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.