473,473 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2398
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.