Current location: Hot Scripts Forums » Programming Languages » PHP » Downloadeing files in php


Downloadeing files in php

Reply
  #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); 
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-12-09, 12:29 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
PHP Code:

$update mysql_query("UPDATE `files` SET `downloaded` = downloaded + 1 WHERE `filename` = "'". $_REQUEST['filename'] ."'"); 

will update your database by adding the column by one.

I would steer clear of using $_REQUEST, and use the specific $_GET, or $_POST array's.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-12-09, 01:20 PM
Wanasa Wanasa is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
thankx Jcbnes aloooot.
still do anyone know how to do the download thing !!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-12-09, 04:01 PM
=OTS=G-Man =OTS=G-Man is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
as far as I know. the yellow bar is just in IE, and is from the default security settings in IE6 and up to warn people about a download thats trying to download.

If you wanted to recreate it, I have seen it down using CSS and javascript.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-12-09, 09:31 PM
Wanasa Wanasa is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
no man am talking about the submiting queries while using headers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-13-09, 07:54 AM
Wanasa Wanasa is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
this is the final code but its not woeking if the update line exists else it works
PHP Code:

<?php


/* HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH *\
-------------------------------------------------------------------------------
#                            #
#    P.V. SHARE v1.0                    #
#    System Copy Type : FULL COPY            #
#    P.V. SHARE COMPANY - www.pvshare.com        #
#    Last Modify : 01/04/09                #
#    -----------------------------------------------------------    #
#    FILE CONTENT :                    #
#    this file holdes the download function to brevint        #
#    knowing the file real source                #
#                            #
--------------------------------------------------------------------------------
\* HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH */



# 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;

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

if($_GET['filename'] && $_GET['nickname']) {

    
# update the number of downloadeds by one
    
$update mysql_query("UPDATE `files` SET `downloaded` = downloaded + 1 WHERE `filename` = "'". $_GET['filename'] ."'");



    
$GETed_file = $_GET['nickname'] . "___" . $_GET['filename'];

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

    
$size = filesize ($download_path . $GETed_file);


    set_time_limit(0);

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

    ob_clean();
    flush();

    readfile(
$download_path . $GETed_file);  
    exit();

} else {

    exit();

}




?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-13-09, 09:13 AM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Try this, there was an error with your double quotes in the $update line.

PHP Code:

<?php

/* HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH *\
-------------------------------------------------------------------------------
#                            #
#    P.V. SHARE v1.0                    #
#    System Copy Type : FULL COPY            #
#    P.V. SHARE COMPANY - www.pvshare.com        #
#    Last Modify : 01/04/09                #
#    -----------------------------------------------------------    #
#    FILE CONTENT :                    #
#    this file holdes the download function to brevint        #
#    knowing the file real source                #
#                            #
--------------------------------------------------------------------------------
\* HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH */



# 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;

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

if($_GET['filename'] && $_GET['nickname']) {

    
# update the number of downloadeds by one
    
$update mysql_query("UPDATE `files` SET `downloaded` = downloaded + 1 WHERE `filename` = ' "$_GET['filename'] ."'");



    
$GETed_file $_GET['nickname'] . "___" $_GET['filename'];

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

    
$size filesize ($download_path $GETed_file);


    
set_time_limit(0);

    
header("Content-Type: application/octet-stream"); 
    
header("Content-Disposition: attachment; filename=" $_GET['filename']); 
    
header ('Expires: 0'); 
    
header ('Last-Modified: ' gmdate ('D, d M Y H:i:s'filemtime ($GETed_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'); 

    
ob_clean();
    
flush();

    
readfile($download_path $GETed_file);  
    exit();

} else {

    exit();

}




?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP in text files from lead, how? jeppchen PHP 2 04-22-09 01:24 PM
create files in php banli PHP 3 10-31-08 10:49 PM
Uploading files into server using PHP and MySQL sccc2008 Script Requests 1 01-26-07 03:19 AM
php files with no extension? liljoeyjordison PHP 4 09-03-05 02:46 PM
PHP Runner , Preview PHP files ! moslehi@gmail.com General Advertisements 3 12-08-04 04:01 PM


All times are GMT -5. The time now is 02:21 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.