PluginProbe
WP Synchro – The Ultimate WordPress Migration Tool / trunk
WP Synchro – The Ultimate WordPress Migration Tool vtrunk
1.16.1 1.16.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.11.5 1.12.0 1.13.0 1.14.0 1.15.0 1.2.0 1.3.0 1.3.1 1.3.2 All 45 releases
wpsynchro / src / API / DownloadLogDBBackup.php

DownloadLogDBBackup.php in WP Synchro – The Ultimate WordPress Migration Tool trunk, at src/API/DownloadLogDBBackup.php

57 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPSynchro\API;
4
5 use WPSynchro\Utilities\PluginDirs;
6
7 /**
8 * Class for handling service to download database backups
9 * Call should already be verified by permissions callback
10 */
11 class DownloadLogDBBackup extends WPSynchroService
12 {
13 public function service()
14 {
15 if (!isset($_REQUEST['job_id']) || strlen($_REQUEST['job_id']) == 0) {
16 $result = new \StdClass();
17 echo json_encode($result);
18 http_response_code(400);
19 return;
20 }
21 $job_id = sanitize_key($_REQUEST['job_id']);
22
23 $filename = "database_backup_" . $job_id . ".sql";
24 $plugins_dirs = new PluginDirs();
25 $log_path = $plugins_dirs->getUploadsFilePath();
26
27 if (!file_exists($log_path . $filename)) {
28 http_response_code(400);
29 return;
30 }
31
32 $log_contents = file_get_contents($log_path . $filename);
33
34 $zipfilename = "wpsynchro_db_backup_" . $job_id . ".zip";
35
36 http_response_code(200); // IIS fails if this is not here
37 header("Pragma: public");
38 header("Expires: 0");
39 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
40 header("Cache-Control: public");
41 header("Content-Description: File Transfer");
42 header("Content-Type: application/zip");
43 header("Content-Disposition: attachment; filename=" . $zipfilename);
44
45 $zipfile = tempnam($log_path, "zip");
46 $zip = new \ZipArchive();
47 $zip->open($zipfile, \ZipArchive::OVERWRITE);
48 $zip->addFromString($filename, $log_contents);
49 $zip->close();
50
51 readfile($zipfile);
52 unlink($zipfile);
53
54 exit();
55 }
56 }
57