diff options
author | piernov <piernov@piernov.org> | 2016-05-04 14:27:35 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-05-04 14:27:35 +0200 |
commit | 9ce1da5147b3df01812687562faca80623b27a38 (patch) | |
tree | bdccb125445fd4b546889ebf25eb9c2d4b1c7956 /inc/savegame.inc | |
parent | 40b0d42dee76bc62517801aa746371a9ce2895a1 (diff) | |
download | candybox-9ce1da5147b3df01812687562faca80623b27a38.tar.gz candybox-9ce1da5147b3df01812687562faca80623b27a38.tar.bz2 candybox-9ce1da5147b3df01812687562faca80623b27a38.tar.xz candybox-9ce1da5147b3df01812687562faca80623b27a38.zip |
Receive uploaded savegame from PHP
Diffstat (limited to 'inc/savegame.inc')
-rw-r--r-- | inc/savegame.inc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/inc/savegame.inc b/inc/savegame.inc index 1fa95b0..8772585 100644 --- a/inc/savegame.inc +++ b/inc/savegame.inc @@ -89,4 +89,24 @@ function loadSave() { $_SESSION = array(); // drop current game parseSave($xml, $_SESSION); } + +function uploadSave() { + $fname = basename($_FILES['savefile']['name']); + $src = $_FILES['savefile']['tmp_name']; + + libxml_use_internal_errors(true); // Ignore errors when loading the received file + $xml = simplexml_load_file($src); + libxml_use_internal_errors(false); + if(!$xml) { + sendError("upload_fail"); + return; + } + $table = array(); + parseSave($xml, $table); // Parse received file + + $save = new SimpleXMLElement("<save/>"); + genXML($table, $save); // Regenerate it + if($save->asXML(SAVEDIR."/".$fname)) sendInfo("upload_success", array($fname)); + else sendError("upload_error"); +} ?> |