473,233 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

File Download Through Hyper Link?


I'd like to write to a log whenever a visitor to my site downloads a
file. So, I'd like the link they click to be to a php 'page' that
returns the file. Don't know how to do that!

Side Question ...

Presumably, the dialog that you see when you download a binary (asking
for a 'Save As...' file name) is put up by your browser when it 'sees'
non-text data coming back as a response? So, how would you download a
text file - and cause this dialog to appear at the user's end?

Thanks!

pemo
Jul 17 '05 #1
5 5799
On Wed, 26 Nov 2003 10:49:12 GMT, peetm <jg********@blueyonder.co.uk>
wrote:

I'd like to write to a log whenever a visitor to my site downloads a
file. So, I'd like the link they click to be to a php 'page' that
returns the file. Don't know how to do that!

Just pass to the php page an id for the file that has to download and
then redirect (with javascript for example) to the file.
Side Question ...

Presumably, the dialog that you see when you download a binary (asking
for a 'Save As...' file name) is put up by your browser when it 'sees'
non-text data coming back as a response? So, how would you download a
text file - and cause this dialog to appear at the user's end?

Well, i think that this dialog doesnt appear because the file is
binary, he appears because the browser doesnt know how "manage" that
file. Files with extension swf for example are binaries and the
browser doesnt show that dialog.

If you want to log the acces to that files (txt files) just redirect
to this files from the php page too. But if you want to show the
dialog i dont know, maybe with javascript you can, has to be something
like save the page.
Thanks!

pemo


Not at all, and sorry my english ;-)
Jul 17 '05 #2
Looking at php.net I thought this would work ...

<?php

$filename='./' . $_GET['name'];

$fp=fopen($filename, "r");

$contents = fread ($fp, filesize($filename));

fclose($fp);

@readfile($filename);

// just does the same.
//
//echo $contents;

?>

but I just get a load of garbage as a result (the binary 'made text'
really)

pemo
On Wed, 26 Nov 2003 10:49:12 GMT, peetm <jg********@blueyonder.co.uk>
wrote:

I'd like to write to a log whenever a visitor to my site downloads a
file. So, I'd like the link they click to be to a php 'page' that
returns the file. Don't know how to do that!

Side Question ...

Presumably, the dialog that you see when you download a binary (asking
for a 'Save As...' file name) is put up by your browser when it 'sees'
non-text data coming back as a response? So, how would you download a
text file - and cause this dialog to appear at the user's end?

Thanks!

pemo


Jul 17 '05 #3
You need to get the appropriate HTTP header so that IE doesn't think
that it's an HTML page/

<?php

$filename = $_GET['filename'];
$path = "/somewhere";

/* log the download here */

header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename");

readfile("$path/$filename");

?>

You can also do a HTTP redirect to the file

<?php

$filename = $_GET['filename'];
$url_root = "/somewhere";

/* log the download here */

header("Location: $url_root/$filename");

?>

This is safer than the first method, as in this case the web server
controls which files the user has access to. Doing a readfile() means
having to do that yourself in order to ensure that you're not exposing
files not meant for the public (e.g. PHP files).

peetm <jg********@blueyonder.co.uk> wrote in message news:<6m********************************@4ax.com>. ..
Looking at php.net I thought this would work ...

<?php

$filename='./' . $_GET['name'];

$fp=fopen($filename, "r");

$contents = fread ($fp, filesize($filename));

fclose($fp);

@readfile($filename);

// just does the same.
//
//echo $contents;

?>

but I just get a load of garbage as a result (the binary 'made text'
really)

pemo
On Wed, 26 Nov 2003 10:49:12 GMT, peetm <jg********@blueyonder.co.uk>
wrote:

I'd like to write to a log whenever a visitor to my site downloads a
file. So, I'd like the link they click to be to a php 'page' that
returns the file. Don't know how to do that!

Side Question ...

Presumably, the dialog that you see when you download a binary (asking
for a 'Save As...' file name) is put up by your browser when it 'sees'
non-text data coming back as a response? So, how would you download a
text file - and cause this dialog to appear at the user's end?

Thanks!

pemo

Jul 17 '05 #4
The following (below) worked - although the 'Save As' dialog prompts
the user to save the file as 'files' (that's the name of my php page,
e.g., http://www.blah.com/files.php?name=thing.zip) and not as
'thing.zip' - is there anyway to correct that?

(btw, I didn't know you could 'quote' a variable like that
(readfile("$filename");) - is there any difference between
readfile("$filename"); and readfile($filename);

pemo

<?php

$filename='./' . $_GET['name'];

/* log the download here */

header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename");

readfile("$filename");

?>

On 26 Nov 2003 21:38:07 -0800, ch***********@hotmail.com (Chung Leong)
wrote:
You need to get the appropriate HTTP header so that IE doesn't think
that it's an HTML page/

<?php

$filename = $_GET['filename'];
$path = "/somewhere";

/* log the download here */

header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename");

readfile("$path/$filename");

?>

You can also do a HTTP redirect to the file

<?php

$filename = $_GET['filename'];
$url_root = "/somewhere";

/* log the download here */

header("Location: $url_root/$filename");

?>

This is safer than the first method, as in this case the web server
controls which files the user has access to. Doing a readfile() means
having to do that yourself in order to ensure that you're not exposing
files not meant for the public (e.g. PHP files).

peetm <jg********@blueyonder.co.uk> wrote in message news:<6m********************************@4ax.com>. ..
Looking at php.net I thought this would work ...

<?php

$filename='./' . $_GET['name'];

$fp=fopen($filename, "r");

$contents = fread ($fp, filesize($filename));

fclose($fp);

@readfile($filename);

// just does the same.
//
//echo $contents;

?>

but I just get a load of garbage as a result (the binary 'made text'
really)

pemo
On Wed, 26 Nov 2003 10:49:12 GMT, peetm <jg********@blueyonder.co.uk>
wrote:
>
>I'd like to write to a log whenever a visitor to my site downloads a
>file. So, I'd like the link they click to be to a php 'page' that
>returns the file. Don't know how to do that!
>
>Side Question ...
>
>Presumably, the dialog that you see when you download a binary (asking
>for a 'Save As...' file name) is put up by your browser when it 'sees'
>non-text data coming back as a response? So, how would you download a
>text file - and cause this dialog to appear at the user's end?
>
>Thanks!
>
>pemo


Jul 17 '05 #5
Which browser are you using? IE 5.5 has a bug which causes the
syndrome you described. See this knowledge base article:

http://support.microsoft.com/default...b;en-us;303750

Check the PHP manual more info about inserting variables into strings:

http://www.php.net/manual/en/languag....syntax.double

One thing I forgot to mention in my last post is that if auto session
is on, you would need to call session_write_close() before calling
readfile(). Otherwise your visitors wouldn't be able to go to other
parts of your site while the download is occurring (as the session is
locked).

pemo <jg********@blueyonder.co.uk> wrote in message news:<0b********************************@4ax.com>. ..
The following (below) worked - although the 'Save As' dialog prompts
the user to save the file as 'files' (that's the name of my php page,
e.g., http://www.blah.com/files.php?name=thing.zip) and not as
'thing.zip' - is there anyway to correct that?

(btw, I didn't know you could 'quote' a variable like that
(readfile("$filename");) - is there any difference between
readfile("$filename"); and readfile($filename);

pemo

<?php

$filename='./' . $_GET['name'];

/* log the download here */

header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename");

readfile("$filename");

?>

On 26 Nov 2003 21:38:07 -0800, ch***********@hotmail.com (Chung Leong)
wrote:
You need to get the appropriate HTTP header so that IE doesn't think
that it's an HTML page/

<?php

$filename = $_GET['filename'];
$path = "/somewhere";

/* log the download here */

header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename");

readfile("$path/$filename");

?>

You can also do a HTTP redirect to the file

<?php

$filename = $_GET['filename'];
$url_root = "/somewhere";

/* log the download here */

header("Location: $url_root/$filename");

?>

This is safer than the first method, as in this case the web server
controls which files the user has access to. Doing a readfile() means
having to do that yourself in order to ensure that you're not exposing
files not meant for the public (e.g. PHP files).

peetm <jg********@blueyonder.co.uk> wrote in message news:<6m********************************@4ax.com>. ..
Looking at php.net I thought this would work ...

<?php

$filename='./' . $_GET['name'];

$fp=fopen($filename, "r");

$contents = fread ($fp, filesize($filename));

fclose($fp);

@readfile($filename);

// just does the same.
//
//echo $contents;

?>

but I just get a load of garbage as a result (the binary 'made text'
really)

pemo
On Wed, 26 Nov 2003 10:49:12 GMT, peetm <jg********@blueyonder.co.uk>
wrote:

>
>I'd like to write to a log whenever a visitor to my site downloads a
>file. So, I'd like the link they click to be to a php 'page' that
>returns the file. Don't know how to do that!
>
>Side Question ...
>
>Presumably, the dialog that you see when you download a binary (asking
>for a 'Save As...' file name) is put up by your browser when it 'sees'
>non-text data coming back as a response? So, how would you download a
>text file - and cause this dialog to appear at the user's end?
>
>Thanks!
>
>pemo

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bart plessers | last post by:
Hello, Currently I am developping a internet "directory browser" My page 'default.asp' has following entries: CurrentPATH = Request("MyLink") Set oFSO =...
4
by: Glenn Mulno | last post by:
Off the wall question: Is there a way to set a hyperlink so that it opens the newest file in a directory? Why: I have a page that is a link to a daily set of reports. A new report gets...
7
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. ...
2
by: Otis Mukinfus | last post by:
Can someone show me the code required to download a zip file to a user? Thanks, Otis Mukinfus http://www.otismukinfus.com http://www.tomchilders.com
1
by: ramapv | last post by:
Hi to all!!!!! Please help Me!! I am having a web page which consists of three inter related windows(iframes). 1)For typing the msg to be send.(iframe1) 2)To display that msg along with the ...
3
by: ajaspersonal | last post by:
"i want to change font_style (hyper link<a href...>text</a>) normal to italics.when load a page" this is my problem but that label included in one 'USERCONTROL' This user controls may...
1
by: simons | last post by:
Hi All, I'm trying to add a hyper link to one of the filed in my DataList control. I added a link button but could not bound it to an ID filed and then link it to the page that i need. I'm...
14
by: Irfan12 | last post by:
i dont know php & i want a script that when a user click on a mp3 hyperlink, the mp3 file start downloading instead of start playing in media player. i got a sxript from internet search. i am using...
1
by: Kalaram | last post by:
I am makeing a CD, and in this CD i have alot of .pdf & .ppt & .pps files and i have one html page that i use as index to all the files, when i click on the hyper link of .pdf file , it opens...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.