Login   Register  
PHP Classes
elePHPant
Icontem

File: download.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Vincenzo Di Biaggio  >  PHP Digital Download Script  >  download.php  >  Download  
File: download.php
Role: Application script
Content type: text/plain
Description: Application script
Class: PHP Digital Download Script
Serve files for download with codes given to users
Author: By
Last change:
Date: 1 year ago
Size: 976 bytes
 

Contents

Class file image Download
<?php

include(__DIR__.'/digitalDownload.php');
use 
DigitalDownload\DigitalDownload;

$dd = new DigitalDownload();
$dd->install 0;
$dd->downloadsAllowed 1;

if ( 
== $dd->downloadsAllowed && == $dd->install )
{
    
session_start();
    if (!isset(
$_SESSION['abracadabra']) || !isset($_REQUEST['code'])) { die('The spell has failed :(');}
    
    
$code $_REQUEST['inputCode'];
    
    if (
$_SESSION['abracadabra'] !== $_REQUEST['code']) {
        
$f['result'] = 'ko';
        
$f['message'] = 'The spell has failed :(';
        
session_write_close();
        
header("HTTP/1.0 ".$dd->giveResponseCode());
        echo 
json_encode($f);
        
    }
    else {
        
$_SESSION['ctrl'] = sha1($_SESSION['abracadabra']);
        
$dd->download($code);
        
$f['result'] = 'ok';
        
$f['message'] = $dd->giveReturn();
        
header("HTTP/1.0 ".$dd->giveResponseCode());
        echo 
json_encode($f);
    }
    
}
else 
{
    
$f['result'] = 'ko';
    
$f['message'] = 'Download not allowed';
    
session_write_close();
    
header("HTTP/1.0 203");
    echo 
json_encode($f);
}