Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Download File

General discussions related to php

Moderators: macek, egami, gesf

Download File

Postby dhirendrak » Fri Apr 04, 2003 5:24 am

:?:
Hello All,

I already made a file manager. Where session based registered member can manage their files and folder. I want to add a download section in this. Means when any user click on download hyper link the file must start downloading.

I am using following code for this download :

<?
include ("../../main.php");

if(checkses() == false){
header("Location: ../../login.php");
exit();
}
list($u_name,$t_id) = split("\+",$ses_var);

$path="<path where all user folder exists >".$u_name;
$fullpath=stripslashes($path.$FileName);

header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename='$fullpath'");
header("Content-transfer-encoding: binary");
readfile($fullpath);
?>

* $u_name – Name of the user.
$path -- Path where file exists.
$FileName – Name of the file to be download

When I use :
Name : download.php
<?
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$FileName");
header("Content-transfer-encoding: binary");
readfile($FileName);
?>

and Put this download.php file in same folder where all files exists then it works, only problem is browser get hanged some times.

But when I pass full path it will not work properly always try to download with then same script file name (download)
dhirendrak
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Apr 04, 2003 5:10 am
Location: india

Postby Redcircle » Fri Apr 04, 2003 6:35 am

<?
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$FileName");
header("Content-transfer-encoding: binary");
readfile($FULLPATH);
?>
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Window not close

Postby dhirendrak » Fri Apr 04, 2003 10:06 pm

:oops:
Thanks for reply,

I am again facing another problem.When user click on any file name i am openning a new window with the following url :-

download.php?url=/k_map.pdf&FileName=k_map.pdf

With the help of previous post i can download any file without any problem but window will not be closed automaticaly . i tried javascript window close but not working since previously i change the header.

How window will automaticaly closed with save dialog box?????

and another problem is when i use attachement in the following line:
header("Content-Disposition: attachment; filename=$FileName" . "%20");
Then then the IE hangs up sometimes and when i am not using this then download will be limited to some files only i cann't download all files.

At present i am using the following code to in download.php

-------------------------------------
include ("../../main.php");

if(checkses() == false){
header("Location: ../login.php");
exit();
}
list($u_name,$id) = split("\+",$ses_var);

$path="/home/www/htdocs/userfile/".$u_name;
$fullpath=stripslashes($path.$url);

header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$FileName" . "%20");
header("Content-transfer-encoding: binary");
readfile($fullpath);
dhirendrak
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Apr 04, 2003 5:10 am
Location: india

Postby putu » Tue Apr 22, 2003 8:38 pm

why if i make a link to .pdf file , browser always open Acrobat Reader. I just wanna download that file without viewing.
any good code 4 that ?
thanks.
putu
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Apr 22, 2003 1:28 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron