View Single Post
  #1 (permalink)  
Old 06-12-09, 10:28 AM
Wanasa Wanasa is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Downloadeing files in php

hi there,

am working on download script and i want it to work just like realplayer.com and microsoft where a yellow bar is shown at the top of the browser and download the file in most pupular web browser such as Firefox and IE ...

also i want it to count the number of downloads, Here where is submit and update query. is there an query that update fields by adding anumber to it or do i have to do read the field and then do the math thing and update the field again ...

here are the headeres and the code am working on :
when you click on the download link you will be targted to the page download.php and in IE it shows a box to save or to open as or to cancel in firefox it shows to download the file download.php ( which is a problem ) and the page where you've praccess on download link it will remain as it is no refreashin or anything ...

the download.php code is :
PHP Code:

<?php


# including the configuration files and all needed functions files
require_once("includes/config.php");


# SET THE GOLBALES FOR THE SYSTEM
# ------------------------------------------------------

# the defualt variables for the templates in the system
global $vars;

# the settings from the config.php file
global $setting;

# the language file array
global $lang;

# ------------------------------------------------------

# i need to supbmit thies tow queries too. how can it be done with headers and is it the write way !!
/*
# read the numof downloades and update it
$downloaded = mysql_query("SELECT `downloaded` FROM `files` WHERE `filename` = "'". $_REQUEST['filename'] ."'");
# update the number of downloadeds by one
$update = mysql_query("UPDATE `files` SET `downloaded` = '". (#downloaded + 1) ."' WHERE `filename` = "'". $_REQUEST['filename'] ."'");
*/

$requested_file $_REQUEST['nickname'] . "___" $_REQUEST['filename'];

$download_path getSetting('filesdirectory') . "/";

$size filesize ($download_path $requested_file);



    
header("Content-Type: application/octet-stream");
    
header("Content-Disposition: attachment; filename=" $_REQUEST['filename']);
    
header ('Expires: 0');
    
header ('Last-Modified: ' gmdate ('D, d M Y H:i:s'filemtime ($requested_file)) . ' GMT');
    
header ('Pragma: public');
    
header ('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    
header("Content-Type: application/force-download");
    
header("Content-Type: application/download");
    
header ('Accept-Ranges: bytes');
    
header ('Content-Length: ' $size);
    
header ('Connection: close');

    
readfile($download_path $requested_file); 
?>
Reply With Quote