472,980 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Trouble with Mozilla and my PHP download counter

Hi all,

PHP 4.2.2 on RedHat9

I have some files on my website for people to download, and I want to
generate the file location "on the fly", so the URL is held in a database.

I have a simple PHP script, pasted below. IE users are fine, but Mozilla
users actually see the file contents on screen, as garbage, instead of
being presented with the "save as" dialog.

The files for download have the .msi extension (binaries).

Can anyone see what I'm doing wrong? Do I need to send different/additional
headers?

Many thanks!

Jim

===========================================

<?php
// Retrieve the parameters
$FileID = isset($_REQUEST["ID"]) ? $_REQUEST["ID"] : -1;

// Connect to the database
$link = mysql_connect("localhost", root", "xxxxxx") or die("Could not
connect : " . mysql_error());
mysql_select_db("Downloads") or die("Could not select Downloads database");

// Is this a valid download?
$query = "SELECT * FROM DownloadItems WHERE FileID='$FileID'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num_rows = mysql_num_rows($result);

if ($num_rows != 1)
die("Invalid Download");

// Obtain the row
$row = mysql_fetch_array($result, MYSQL_ASSOC);

// Obtain the URL
$FileURL = $row["FileURL"];

// Release the database connection
mysql_free_result($result);

// Redirect
header("Content-Type: application/force-download");
header("Location: $FileURL");
?>

Jim Willsher

Homepages at http://www.jimwillsher.co.uk
Jul 17 '05 #1
11 2368
Jim Willsher wrote:
<?php (snip) // Redirect
header("Content-Type: application/force-download");
header("Location: $FileURL"); No, no! Do not redirect for a new request; use the same request!

Instead of the redirection header, just output the file:

readfile($FileURL);
?>

Happy Coding :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Hi Pedro,

But now the file just gets displayed in Internet Explorer too! This makes
it worse!

Go to http://www.jwillsher.co.uk/Includes/Download2.php?ID=1 to see what I
mean. This is a temporary URL. The normal URL (live on the website) is
http://www.jwillsher.co.uk/Includes/Download.php?ID=1

The webpage itself is at

http://www.jwillsher.co.uk/Site/Software/BRU_Intro.php


Jim

On 22 Feb 2004 16:58:27 GMT, Pedro Graca <he****@hotpop.com> wrote:
Jim Willsher wrote:
<?php

(snip)
// Redirect
header("Content-Type: application/force-download");
header("Location: $FileURL");

No, no! Do not redirect for a new request; use the same request!

Instead of the redirection header, just output the file:

readfile($FileURL);
?>

Happy Coding :)


Jim Willsher

Homepages at http://www.jimwillsher.co.uk
Jul 17 '05 #3
Jim Willsher top posted (corrected):
On 22 Feb 2004 16:58:27 GMT, Pedro Graca <he****@hotpop.com> wrote:
Jim Willsher wrote:
<?php

(snip)
// Redirect
header("Content-Type: application/force-download");
header("Location: $FileURL");

No, no! Do not redirect for a new request; use the same request!

Instead of the redirection header, just output the file:

readfile($FileURL);
?>

But now the file just gets displayed in Internet Explorer too! This makes
it worse!

Go to http://www.jwillsher.co.uk/Includes/Download2.php?ID=1 to see what I
mean. This is a temporary URL. The normal URL (live on the website) is
http://www.jwillsher.co.uk/Includes/Download.php?ID=1

The webpage itself is at

http://www.jwillsher.co.uk/Site/Software/BRU_Intro.php


Please do not top post.

You might want to try different headers.

<?php
// do checks

header('Content-Type: application/binary');
header('Content-Disposition: attachment; filename="' . basename($FileURL) . '"');
readfile($FileURL);
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #4
Hi Pedro,
Please do not top post.
Given that I've been posted to NNTP groups for about 10 years, you're the
first person to ever say that. Perhaps it's different in this NG, but in
all my other groups it's the norm to top-post.
You might want to try different headers.

<?php
// do checks

header('Content-Type: application/binary');
header('Content-Disposition: attachment; filename="' . basename($FileURL) . '"');
readfile($FileURL);
?>


Thanks, I'll give that a try. It looks okay in IE, so I'lll get somebody
with Mozilla to try.

Many thanks,

Jim

Jim Willsher

Homepages at http://www.jimwillsher.co.uk
Jul 17 '05 #5
Jim Willsher wrote:
Hi Pedro,
Please do not top post.
Given that I've been posted to NNTP groups for about 10 years, you're the
first person to ever say that. Perhaps it's different in this NG, but in
all my other groups it's the norm to top-post.


Lots and lots of people top post here too. I just like it better when
they don't :)

I guess you were unlucky to have me in a nitpick mood. Don't change your
habits because of what I say (but thank you for posting the way I like);
I stopped long ago to give a negative score to top-posters, though they
still get a low positive score in my newsreader :)
Thanks, I'll give that a try. It looks okay in IE, so I'lll get somebody
with Mozilla to try.
Works with Mozilla too (I use Firebird).
Many thanks,


You're very welcome.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #6
Pedro Graca wrote:
Works with Mozilla too (I use Firebird).

That's on Windows;

also works with Elinks on Linux -- but with a small glitch: the name of
the download is "Download.php" and not "whatever.msi".
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #7
On 22 Feb 2004 20:19:47 GMT, Pedro Graca <he****@hotpop.com> wrote:
Pedro Graca wrote:
Works with Mozilla too (I use Firebird).

That's on Windows;

also works with Elinks on Linux -- but with a small glitch: the name of
the download is "Download.php" and not "whatever.msi".


Hi Pedro,

Great, excellent news! Many thanks for testing it all out!

Any ideas what would cause the Elinks problem? My knowledge of http headers
is very sketchy, so I don't know if I'm missing anything obvious.

What I'm now doing is:

header('Content-Type: application/binary');
header("Location: $FileURL");

I tried the readfile() thing but it seemed to add a delay to the download.

Thanks again!

Jim

PS I use Agent Newsreader on Windows. Any idea how I'd change it to stop
top-posting? It's not something I had ever considered before, but I'd like
to know how to change it. I can't see an option anywhere!


Jim Willsher

Homepages at http://www.jimwillsher.co.uk
Jul 17 '05 #8
Jim Willsher wrote:
On 22 Feb 2004 20:19:47 GMT, Pedro Graca <he****@hotpop.com> wrote:
Pedro Graca wrote:
Works with Mozilla too (I use Firebird).That's on Windows;

also works with Elinks on Linux -- but with a small glitch: the name of
the download is "Download.php" and not "whatever.msi".

Great, excellent news! Many thanks for testing it all out!

Any ideas what would cause the Elinks problem? My knowledge of http headers
is very sketchy, so I don't know if I'm missing anything obvious.
No idea. But I don't think any Elinks user will want to download a .msi
file :) (and even if they do, they'll think having to type the filename
is ok).
What I'm now doing is:

header('Content-Type: application/binary');
header("Location: $FileURL");
It does *NOT* work now!

You're sending the "Content-Type" header for a page, then redirecting to
another page which will *NOT* have the "Content-Type" and
"Content-Disposition" headers.

In Mozilla the URL http://www.jwillsher.co.uk/Includes/Download2.php?ID=1
asks where to save the file, but the other URLs you provided earlier
just display the file in the browser.
I tried the readfile() thing but it seemed to add a delay to the download.
Strange. The server has to open the file anyway, either with or without
the redirect. Anyway, I think you're stuck with using it (or a similar
function)
http://www.php.net/readfile

PS I use Agent Newsreader on Windows. Any idea how I'd change it to stop
top-posting? It's not something I had ever considered before, but I'd like
to know how to change it. I can't see an option anywhere!


As far as I know (I used Agent before switching [mainly] to Linux) there
is no option for that. Agent puts the cursor at the top of the text,
which is a good place to start editing the previous post by removing
unnecessary lines and adding your own comments.
If you want to write first and edit after that, press Ctrl+End to go to
the end.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #9
On Sun, 22 Feb 2004 22:10:14 +0000, Jim Willsher <ji*@nospam.co.uk>
wrote:
PS I use Agent Newsreader on Windows. Any idea how I'd change it to stop
top-posting? It's not something I had ever considered before, but I'd like
to know how to change it. I can't see an option anywhere!


Just go to the bottom of page with Ctrl+End or Page-Down and start
typing. Though one would usually start by editing out extraneous quoted
material, of course.

HTH

--
Stephen Poley
Jul 17 '05 #10
On 22 Feb 2004 23:47:32 GMT, Pedro Graca <he****@hotpop.com> wrote:
Jim Willsher wrote:
On 22 Feb 2004 20:19:47 GMT, Pedro Graca <he****@hotpop.com> wrote:
Pedro Graca wrote:
Works with Mozilla too (I use Firebird).
That's on Windows;

also works with Elinks on Linux -- but with a small glitch: the name of
the download is "Download.php" and not "whatever.msi".

Great, excellent news! Many thanks for testing it all out!

Any ideas what would cause the Elinks problem? My knowledge of http headers
is very sketchy, so I don't know if I'm missing anything obvious.


No idea. But I don't think any Elinks user will want to download a .msi
file :) (and even if they do, they'll think having to type the filename
is ok).
What I'm now doing is:

header('Content-Type: application/binary');
header("Location: $FileURL");


It does *NOT* work now!

You're sending the "Content-Type" header for a page, then redirecting to
another page which will *NOT* have the "Content-Type" and
"Content-Disposition" headers.

In Mozilla the URL http://www.jwillsher.co.uk/Includes/Download2.php?ID=1
asks where to save the file, but the other URLs you provided earlier
just display the file in the browser.
I tried the readfile() thing but it seemed to add a delay to the download.


Strange. The server has to open the file anyway, either with or without
the redirect. Anyway, I think you're stuck with using it (or a similar
function)
http://www.php.net/readfile

PS I use Agent Newsreader on Windows. Any idea how I'd change it to stop
top-posting? It's not something I had ever considered before, but I'd like
to know how to change it. I can't see an option anywhere!


As far as I know (I used Agent before switching [mainly] to Linux) there
is no option for that. Agent puts the cursor at the top of the text,
which is a good place to start editing the previous post by removing
unnecessary lines and adding your own comments.
If you want to write first and edit after that, press Ctrl+End to go to
the end.


Okay, take two! Could you try this one instead? Normal URL:

http://www.jwillsher.co.uk/Includes/Download.php?ID=1

You'll notice there's about 10 seconds delay from the "website found" to
the save-as dialog appearing. This only happens when I use the readfile()
command.
Jim

Jim Willsher

Homepages at http://www.jimwillsher.co.uk
Jul 17 '05 #11
Jim Willsher wrote:
Okay, take two! Could you try this one instead? Normal URL:

http://www.jwillsher.co.uk/Includes/Download.php?ID=1

You'll notice there's about 10 seconds delay from the "website found" to
the save-as dialog appearing. This only happens when I use the readfile()
command.


Nope. Immediately starts showing 'funny' characters in the browser (be
it Mozilla or Elinks).
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #12

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

Similar topics

6
by: Fernando Rodríguez | last post by:
Hi, I haven't used Python in quite some time, and I'm bit puzzled by this: counter = 0 class Blah(object): def run(self): counter += 1
17
by: George Hester | last post by:
http://tinyurl.com/5uj6w The lower middle icon the "block" should not drop down when the mouse is over it. How can I stop that? Also the navigation divs both top and bottom should follow the...
0
by: Marius III | last post by:
Hi there, I am building a File download counter in PHP5. It's working fine but the problem is that its not working with any Download Managers for ex: Free Download Manager / DAP etc. The...
5
by: Mickey | last post by:
Hi all, Is there a way to find out when a user has completed a download? I ask this because I have a current system where users download files, however due to serious bandwidth issues I need...
7
by: mistral | last post by:
I use htaccess to protect directory and granting access to download file only for the authorized users. Just want implement simple PHP file download counter for single file. I need track the number...
9
by: johnd126 | last post by:
I have a cgi program which outputs a fairly hefty amount of html/javascript for doing a complex slide show sorta thing in a variety of areas in the browser. I accomplish this by creating a series...
12
by: devospice | last post by:
Hi, I'm trying to create a download counter for individual files on a web site and I'm not sure how to do this. Right now I'm using Webalizer to just read the log files and see how many times...
4
by: agun | last post by:
Hello, Hi, i'm really a newbie in programming, especially javascript. I have one question in my mind right now. Sorry before if i'm not clear. Please see this example: ...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.