File tree Expand file tree Collapse file tree
modules/Backup/Controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,15 +95,35 @@ public function restore()
9595 $ file ->move ($ uploadPath , $ newName );
9696 $ filePath = WRITEPATH . 'uploads/ ' . $ newName ;
9797 $ sqlPath = $ filePath ;
98- if ($ ext === 'zip ' ) {
98+ if ($ ext === 'zip ' ) {
9999 $ zip = new \ZipArchive ();
100100 if ($ zip ->open ($ filePath ) === true ) {
101- $ zip ->extractTo ($ uploadPath );
102- $ sqlPath = $ uploadPath . $ zip ->getNameIndex (0 );
101+ $ extractedSql = '' ;
102+ for ($ i = 0 ; $ i < $ zip ->numFiles ; $ i ++) {
103+ $ entryName = $ zip ->getNameIndex ($ i );
104+ $ safeEntryName = basename ($ entryName );
105+
106+ if (preg_match ('/\.sql$/i ' , $ safeEntryName )) {
107+ $ fileContent = $ zip ->getFromIndex ($ i );
108+ $ extractedSql = $ uploadPath . $ safeEntryName ;
109+ file_put_contents ($ extractedSql , $ fileContent );
110+ break ;
111+ }
112+ }
103113 $ zip ->close ();
104114 @unlink ($ filePath );
115+
116+ if (empty ($ extractedSql )) {
117+ return redirect ()->route ('backup ' )->with ('error ' , lang ('Backup.dbNotRestore ' ));
118+ }
119+ $ sqlPath = $ extractedSql ;
120+ } else {
121+ @unlink ($ filePath );
122+ return redirect ()->route ('backup ' )->with ('error ' , lang ('Backup.dbNotRestore ' ));
105123 }
106124 }
125+ }
126+ }
107127
108128 $ dbBackup = new \Modules \Backup \Libraries \DbBackup ();
109129 if ($ dbBackup->restore($ sqlPath)) {
You can’t perform that action at this time.
0 commit comments