Trying to implement an automatic update system for MediaFrontPage (from Github) using PHP.
So far it downloads a Zip file called Update.zip and extracts it to /update
http://localhost/update
In this folder is the latest commit from Github for MediaFrontPage. From here we are trying to move all the folders from there to the root folder recursively but the problem is to do with Permissions (although all files are chmodded to 777 on first install).
Here is the update.php so far.
https://raw.github.com/DejaVu77/mediafrontpage/master/update.php
My PHP Skills are crap and the fella that's made this update script is in the process of learning and has done a great job so far, but it's one of those weird problems we cannot solve.
We cannot use any server side (shell_exec) because the program is cross platform (or so I understand it).
Has anyone got any suggestions as to how we can edit this update.php file to ensure it overwrites all the files in the root directory without moaning about permissions?
Or better still, the ability to edit the file so it moves the files or folder to the destination without the CHMOD errors.
Here's the script it falls over at -
Had to quote the code as CODE and PHP Tag kills the formatting!function moveDownload($src,$dst){
$dir = opendir($src);
while(false !== ($file = readdir($dir))){
if (($file != '.') && ($file != '..') && ($file != 'config.ini') && ($file != 'layout.php') && ($file != 'sbpcache') && ($file !='update')){
if (is_dir($src.'/'.$file)){
if(file_exists($dst.'/'.$file)){
rrmdir($dst.'/'.$file);
}
}
if(@rename($src . '/' . $file, $dst . '/' . $file)){
echo '<tr><td>'.$file.' moved successfully </td><td><font color="green">OK</font></td></tr>';
} else {
if(@chmod($src.'/'.$file, 0777)){
if(@rename($src . '/' . $file, $dst . '/' . $file)){
echo '<tr><td>'.$file.' moved successfully </td><td><font color="green">OK</font></td></tr>';
} else {
echo '<tr><td>Could not move file '.$file.'</td><td><font color="red">ERROR RENAME</font></td></tr>';
}
} else {
echo '<tr><td>Could not move file '.$file.'</td><td><font color="red">ERROR CHMOD</font></td></tr>';
}
}
}
}
closedir($dir);
}
This is the visual result of what is happening at the client side -
error.jpg
Social Networking Bookmarks