PHP Classes

File: download.php

Recommend this page to a friend!
  Classes of Olaf Lederer   Backup4WP   download.php   Download  
File: download.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Backup4WP
Backup and restore your WordPress website
Author: By
Last change:
Date: 11 months ago
Size: 1,049 bytes
 

Contents

Class file image Download
<?php
include_once 'libs/func.php';
if (
false == check_cookie()) {
    die(
'Unauthorized access!');
}
if (!
ENABLE_DOWNLOADS) {
    die(
'Downloads are disabled.');
} else {
    if (!empty(
$_GET['dlid'])) {
        if (
$db = new SQLite3(DATAPATH.'wpbackupsDb.sqlite')) {
           
$sth = $db->prepare("SELECT dirname FROM wpbackups WHERE id = :id");
           
$sth->bindValue(':id', $_GET['dlid'], SQLITE3_INTEGER);
           
$res = $sth->execute();
            if (
$result = $res->fetchArray()) {
               
$archive_file_name = $result['dirname'].'.zip';
               
$archive_path = DATAPATH.$result['dirname'].'/';
               
$str = sprintf('cd ../../backups/ && zip -r %s %s', $archive_path.$archive_file_name, $result['dirname']);
               
exec($str);
               
header("Content-type: application/zip");
               
header("Content-Disposition: attachment; filename=" . $archive_file_name);
               
header("Content-length: " . filesize($archive_path.$archive_file_name));
               
header("Pragma: no-cache");
               
header("Expires: 0");
               
readfile($archive_path.$archive_file_name);
                exit;
            } else {
               
// show some error
           
}
        }
    }
}