我使用PHP将主repo zip从Github保存到一个临时文件夹,提取它然后移动文件夹&文件到主位置,但文件夹&如果我将移动目标设置为新文件夹,则文件不会移动到根文件夹上。
问题可能与文件夹&文件权限,因为这个根文件夹是Magento平台,并具有chmod Magento设置.
Sync.php文件//save to folder
$sync_address = 'tmp';
//move to folder
$sync_move = getcwd().'';
//save master to server
$f = file_put_contents("tmp.zip", fopen("https://github.com/MyGithub/MyRepo/archive/master.zip", 'r'), LOCK_EX);
if(FALSE === $f)
echo 'Couldn''t write to file<br>';
$zip = new ZipArchive;
//open tmp.zip
$res = $zip->open('tmp.zip');
if ($res === TRUE) {
//extract to tmp folder
$zip->extractTo($sync_address);
$zip->close();
echo 'Successfully opened or extracted zip file.<br>';
} else {
echo 'Falied opening or extracting zip file.<br>';
}
//foreach extracted folder only in tmp (as we only want folder & files inside the first github archive folder IE MyRepo-master.zip/MyRepo/actual structure
$directories = glob($sync_address . '/*' , GLOB_ONLYDIR);
foreach($directories as $dir) {
$directoriesSync = glob($dir . '/*');
echo '<br>'.$dir.' Folder Exists <br>';
//move files & folders to root folder
//does not work, no files moved
//works if move folder set as root folder/another folder/
rename($dir, $sync_move);
//for each directory & file move via cmd
//move files & folders to root folder
//does not work, no files moved
//works if move folder set as root folder/another folder/
foreach($directoriesSync as $dirSync) {
shell_exec('mv '.$dirSync.' '.$sync_move.'');
echo 'Successfully moved '.$dirSync.' to '.$sync_move.'<br>';
}
}
变化
shell_exec('mv '.$dirSync.' '.$sync_move.'');
shell_exec("cp -r $dirSync $sync_move");
并成功运行