Enterprise3.01 > Download.php

Questions? Need Help? Want to share? » PHP Forum
Script Name:
Enterprise3.01

Download:
enterprise3.01.zip

Category:
E Commerce

Archive Content:

Content:

Admin

Admin > Htmlarea

Admin > Htmlarea > Images

Admin > Htmlarea > Popups

Admin > Htmlarea > Popups > File

Admin > Htmlarea > Popups > File > Icons

Admin > Htmlarea > Popups > File > Images

Admin > Images

Admin > Images > Categories

Admin > Images > Graphs

Admin > Images > Icons

Admin > Includes

Admin > Includes > Boxes

Admin > Includes > Classes

Admin > Includes > Functions

Admin > Includes > Graphs

Admin > Includes > Javascript

Admin > Includes > Javascript > SpiffyCal

Admin > Includes > Javascript > SpiffyCal > Images

Admin > Includes > Languages

Admin > Includes > Languages > English

Admin > Includes > Languages > English > CVS

Admin > Includes > Languages > English > Images > Buttons

Admin > Includes > Languages > English > Images > Buttons > CVS

Admin > Includes > Languages > English > Images > Copy Of Buttons

Admin > Includes > Languages > English > Images > Copy Of Buttons > CVS

Admin > Includes > Languages > English > Images > CVS

Admin > Includes > Languages > English > Modules > Newsletters

Admin > Includes > Languages > Espanol

Admin > Includes > Languages > Espanol > CVS

Admin > Includes > Languages > Espanol > Images > Buttons

Admin > Includes > Languages > Espanol > Images > Buttons > CVS

Admin > Includes > Languages > Espanol > Images > CVS

Admin > Includes > Languages > Espanol > Modules > Newsletters

Admin > Includes > Languages > German

Admin > Includes > Languages > German > CVS

Admin > Includes > Languages > German > Images > Buttons

Admin > Includes > Languages > German > Images > Buttons > CVS

Admin > Includes > Languages > German > Images > CVS

Admin > Includes > Languages > German > Modules > Newsletters

Admin > Includes > Local

Admin > Includes > Modules > Newsletters

Admin > Live Support

Admin > Live Support > Blue

Admin > Live Support > Green

Admin > Live Support > Red

Admin > Live Support > White

Admin > Live Support > Yellow

Download

Images

Images > Banners

Images > Default

Images > Icons

Images > Infobox

Images > Mail

Includes

Includes > Boxes

Includes > Classes

Includes > Color Schemes > 1

Includes > Color Schemes > 10

Includes > Color Schemes > 11

Includes > Color Schemes > 12

Includes > Color Schemes > 2

Includes > Color Schemes > 3

Includes > Color Schemes > 4

Includes > Color Schemes > 5

Includes > Color Schemes > 6

Includes > Color Schemes > 7

Includes > Color Schemes > 8

Includes > Color Schemes > 9

Includes > Functions

Includes > Javascript

Includes > Languages

Includes > Languages > English

Includes > Languages > English > CVS

Includes > Languages > English > Images

Includes > Languages > English > Images > Buttons

Includes > Languages > English > Images > Buttons > CVS

Includes > Languages > English > Images > CVS

Includes > Languages > English > Modules > Order Total

Includes > Languages > English > Modules > Payment

Includes > Languages > English > Modules > Shipping

Includes > Languages > Espanol

Includes > Languages > Espanol > CVS

Includes > Languages > Espanol > Images

Includes > Languages > Espanol > Images > Buttons

Includes > Languages > Espanol > Images > Buttons > CVS

Includes > Languages > Espanol > Images > CVS

Includes > Languages > Espanol > Modules > Order Total

Includes > Languages > Espanol > Modules > Payment

Includes > Languages > Espanol > Modules > Shipping

Includes > Languages > French

Includes > Languages > French > Images > Buttons

Includes > Languages > French > Modules > Payment

Includes > Languages > German

Includes > Languages > German > CVS

Includes > Languages > German > Images

Includes > Languages > German > Images > Buttons

Includes > Languages > German > Images > Buttons > CVS

Includes > Languages > German > Images > CVS

Includes > Languages > German > Modules > Order Total

Includes > Languages > German > Modules > Payment

Includes > Languages > German > Modules > Shipping

Includes > Local

Includes > Modules

Includes > Modules > Order Total

Includes > Modules > Payment

Includes > Modules > Shipping

Install

Install > Images

Install > Images > Layout

Install > Includes

Install > Includes > Functions

Install > Templates

Install > Templates > Main Page

Install > Templates > Pages

Live Support

Live Support > Blue

Live Support > Green

Live Support > Red

Live Support > White

Live Support > Yellow

Members

Members > Cashhub

Members > Cashhub > Images

Members > User

Members > User > Test Dir

Templates

Templates > Content

Download.php:


<?php
/*
  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  Enterprise Shopping Cart
  http://www.enterprisecart.com

  Copyright (c) 2004 Enterprise Shopping Cart Software.  Portions Copyright (c) 2001-2004 osCommerce: http://www.oscommerce.com

  Released under the GNU General Public License
*/

    
include('includes/application_top.php');

    if (!
escs_session_is_registered('customer_id')) die;

    
// Check download.php was called with proper GET parameters
    
if ((isset($HTTP_GET_VARS['order']) && !is_numeric($HTTP_GET_VARS['order'])) || (isset($HTTP_GET_VARS['id']) && !is_numeric($HTTP_GET_VARS['id'])) )
    {
        die;
    }

    
// Check that order_id,  customer_id and filename match
    
$downloads_query escs_db_query("select date_format(o.date_purchased,  '%Y-%m-%d') as date_purchased_day,  opd.download_maxdays,  opd.download_count,  opd.download_maxdays,  opd.orders_products_filename from " TABLE_ORDERS " o,  " TABLE_ORDERS_PRODUCTS " op,  " TABLE_ORDERS_PRODUCTS_DOWNLOAD " opd where o.customers_id = '" $customer_id "' and o.orders_id = '" . (int)$HTTP_GET_VARS['order'] . "' and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "' and opd.orders_products_filename != ''");

    if (!
escs_db_num_rows($downloads_query)) 
        die;

    
$downloads escs_db_fetch_array($downloads_query);

    
// MySQL 3.22 does not have INTERVAL

    
list($dt_year,  $dt_month,  $dt_day) = explode('-',  $downloads['date_purchased_day']);
    
$download_timestamp mktime(23,  59,  59,  $dt_month,  $dt_day $downloads['download_maxdays'],  $dt_year);

    
// Die if time expired (maxdays = 0 means no time limit)
    
if (($downloads['download_maxdays'] != 0) && ($download_timestamp <= time()))
        die;

    
// Die if remaining count is <=0
    
if ($downloads['download_count'] <= 0)
        die;

    
// Die if file is not there
    
if (!file_exists(DIR_FS_DOWNLOAD $downloads['orders_products_filename'])) die;

    
// Now decrement counter

    
escs_db_query("update " TABLE_ORDERS_PRODUCTS_DOWNLOAD " set download_count = download_count-1 where orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "'");

    
// Returns a random name,  16 to 20 characters long
    // There are more than 10^28 combinations
    // The directory is "hidden",  i.e. starts with '.'

    
function escs_random_name()
    {
        
$letters 'abcdefghijklmnopqrstuvwxyz';
        
$dirname '.';
        
$length floor(escs_rand(16, 20));
        for (
$i 1$i <= $length$i++)
        {
            
$q floor(escs_rand(1, 26));
            
$dirname .= $letters[$q];
        }
        return 
$dirname;
    }

    
// Unlinks all subdirectories and files in $dir
    // Works only on one subdir level,  will not recurse

    
function escs_unlink_temp_dir($dir)
    {
        
$h1 opendir($dir);
        while (
$subdir readdir($h1))
        {
            
// Ignore non directories
            
if (!is_dir($dir $subdir))
                continue;
            
// Ignore . and .. and CVS
            
if ($subdir == '.' || $subdir == '..' || $subdir == 'CVS')
                continue;
            
// Loop and unlink files in subdirectory
            
$h2 opendir($dir $subdir);
            while (
$file readdir($h2))
            {
                if (
$file == '.' || $file == '..')
                    continue;
                @
unlink($dir $subdir '/' $file);
            }
            
closedir($h2);
            @
rmdir($dir $subdir);
        }
        
closedir($h1);
    }

    
// Now send the file with header() magic

    
header("Expires: Mon,  26 Nov 1962 00:00:00 GMT");
    
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
    
header("Cache-Control: no-cache,  must-revalidate");
    
header("Pragma: no-cache");
    
header("Content-Type: Application/octet-stream");
    
header("Content-disposition: attachment; filename=" $downloads['orders_products_filename']);

    
readfile(DIR_FS_DOWNLOAD $downloads['orders_products_filename']);

    
/*    
    if (DOWNLOAD_BY_REDIRECT == 'true')
    {
        // This will work only on Unix/Linux hosts
        escs_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC);
        $tempdir = escs_random_name();
        umask(0000);
        mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir,  0777);
        symlink(DIR_FS_DOWNLOAD . $downloads['orders_products_filename'],  DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename']);
        escs_redirect(DIR_WS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename']);
    }
    else
    {
        // This will work on all systems,  but will need considerable resources
        // We could also loop with fread($fp,  4096) to save memory
        readfile(DIR_FS_DOWNLOAD . $downloads['orders_products_filename']);
    }
    */
?>


Other E Commerce Scripts:

WebMaster Resources Home

©RingsWorld.com