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 @@ -96,15 +96,35 @@ public function restore()
9696 $ file ->move ($ uploadPath , $ newName );
9797 $ filePath = WRITEPATH . 'uploads/ ' . $ newName ;
9898 $ sqlPath = $ filePath ;
99- if ($ ext === 'zip ' ) {
99+ if ($ ext === 'zip ' ) {
100100 $ zip = new \ZipArchive ();
101101 if ($ zip ->open ($ filePath ) === true ) {
102- $ zip ->extractTo ($ uploadPath );
103- $ sqlPath = $ uploadPath . $ zip ->getNameIndex (0 );
102+ $ extractedSql = '' ;
103+ for ($ i = 0 ; $ i < $ zip ->numFiles ; $ i ++) {
104+ $ entryName = $ zip ->getNameIndex ($ i );
105+ $ safeEntryName = basename ($ entryName );
106+
107+ if (preg_match ('/\.sql$/i ' , $ safeEntryName )) {
108+ $ fileContent = $ zip ->getFromIndex ($ i );
109+ $ extractedSql = $ uploadPath . $ safeEntryName ;
110+ file_put_contents ($ extractedSql , $ fileContent );
111+ break ;
112+ }
113+ }
104114 $ zip ->close ();
105115 @unlink ($ filePath );
116+
117+ if (empty ($ extractedSql )) {
118+ return redirect ()->route ('backup ' )->with ('error ' , lang ('Backup.dbNotRestore ' ));
119+ }
120+ $ sqlPath = $ extractedSql ;
121+ } else {
122+ @unlink ($ filePath );
123+ return redirect ()->route ('backup ' )->with ('error ' , lang ('Backup.dbNotRestore ' ));
106124 }
107125 }
126+ }
127+ }
108128
109129 $ dbBackup = new \Modules \Backup \Libraries \DbBackup ();
110130 if ($ dbBackup->restore($ sqlPath)) {
You can’t perform that action at this time.
0 commit comments