By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,456 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,456 IT Pros & Developers. It's quick & easy.

Want to make a link anchor call a PHP script

P: n/a
Think I asked this once before. My apologies for asking twice.

In a certain PHP document at my site, I have a link to a Word version of the
same document. If the user downloads it, I want to log that s/he has done this.
Data logging isn't the issue. Calling a PHP script is.

So what I have is something like:

<a href=http://my-web-site.com/documents/mydoc.doc>Click here</a> to
download a Word version of this document.

Of course the <a> anchor exists only on the client side and the PHP script
exists only on the server. But since clicking the anchor sends a message to the
server, there ought to be a linkage that can be exploited to enable a PHP call.
I just can't think of one.

Any ideas?



Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies

P: n/a
"JimC" <ji**@cross-comp.com> wrote in message
news:G%*****************@newssvr29.news.prodigy.co m...
Think I asked this once before. My apologies for asking twice.

In a certain PHP document at my site, I have a link to a Word version of the same document. If the user downloads it, I want to log that s/he has done this. Data logging isn't the issue. Calling a PHP script is.

So what I have is something like:

<a href=http://my-web-site.com/documents/mydoc.doc>Click here</a> to
download a Word version of this document.

Of course the <a> anchor exists only on the client side and the PHP script
exists only on the server. But since clicking the anchor sends a message to the server, there ought to be a linkage that can be exploited to enable a PHP call. I just can't think of one.

Any ideas?

Try this:

<a
href="http://my-web-site.com/documents/downloadfile.php?file=mydoc.doc">Clic
k here</a> to
download a Word version of this document.

here is downloadfile.php:

<?php
$wFile = $_GET['file'];

$fp = fopen("logfile.txt","w");
fwrite($fp,"Download $wFile .......what ever else you want to log, such as
ip, etc... \n");
fclose($fp);

$sendFile = "/path/to/files/$wFile";
$clen = filesize($sendFile);
header("Content-type: Application/binary"); // use this so it does get
down loaded not displayed in browser!
header("Content-disposition: filename=\"$zipName\"");
header("Content-length: $clen");
readfile($sendFile);
exit(); // this is to make sure no more data gets sent. and script exits
?>

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2

P: n/a
CountScubula wrote:
header("Content-type: Application/binary"); // use this so it does get
down loaded not displayed in browser!


Microsoft Word documents already have a registered MIME media type,
so there's no need to make one up. Notice there's an optional version
parameter with this type, which might come in handy.
ftp://ftp.isi.edu/in-notes/iana/assi...s/media-types/

Incidentally, the type application/binary isn't registered; "private
values" should be prefixed with "X-" (case insensitive).

--
Jock
Jul 17 '05 #3

P: n/a
"John Dunlop" <jo*********@johndunlop.info> wrote in message
news:MP************************@news.freeserve.net ...
Microsoft Word documents already have a registered MIME media type,
so there's no need to make one up.
True, however, using the registered one, tells the browser that it is
recieving a word document, and then the browser will try to display it. The
trick is to tell the browser it is a differnt type of file, one that it does
not know what to do with. Heck you could use "Content-type:
IMIU/I-made-it-up", the browser would have no idea what it is recieving, so
it would pop open a save file dialog box.
Incidentally, the type application/binary isn't registered; "private
values" should be prefixed with "X-" (case insensitive).


see above ^

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #4

P: n/a
On 2004-01-05, CountScubula <me@scantek.hotmail.com> wrote:
"John Dunlop" <jo*********@johndunlop.info> wrote in message
news:MP************************@news.freeserve.net ...
Microsoft Word documents already have a registered MIME media type,
so there's no need to make one up.


True, however, using the registered one, tells the browser that it is
recieving a word document, and then the browser will try to display it. The
trick is to tell the browser it is a differnt type of file, one that it does
not know what to do with. Heck you could use "Content-type:
IMIU/I-made-it-up", the browser would have no idea what it is recieving, so
it would pop open a save file dialog box.


That is because the user wants his browser to act that way.
(Or someone else decided for him that his browser should act that way).

I really don't see a good reason to not send the correct content-type in
the header.
--
http://home.mysth.be/~timvw
Jul 17 '05 #5

P: n/a
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:bt************@ID-188825.news.uni-berlin.de...

I really don't see a good reason to not send the correct content-type in
the header.

--
http://home.mysth.be/~timvw

Have you not listed to what I said? True, you are right, it is becouse the
user, or someone decided what to do with those content types.

HOWEVER, ( read this over if you still don't get it! )

When a website wants to enforce a file download, you do not want to send the
correct mime-type.

Example, my browser is set to show .pdf files, if I wanted to make a site
that allowed people to
download a .pdf instead of viewing it, I would NOT SEND Content-type:
application/pdf !

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #6

P: n/a
On 2004-01-06, CountScubula <me@scantek.hotmail.com> wrote:
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:bt************@ID-188825.news.uni-berlin.de...

I really don't see a good reason to not send the correct content-type in
the header.

--
http://home.mysth.be/~timvw

Have you not listed to what I said? True, you are right, it is becouse the
user, or someone decided what to do with those content types.

HOWEVER, ( read this over if you still don't get it! )

When a website wants to enforce a file download, you do not want to send the
correct mime-type.


IMHO it is just silly trying to do something that is impossible.

Providing some text that says: "You might want to try right-clicking on this
link, and choose "save target as" in the context menu to save this file"
seems to be a better solution.

--
http://home.mysth.be/~timvw
Jul 17 '05 #7

P: n/a
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:bt************@ID-188825.news.uni-berlin.de...

IMHO it is just silly trying to do something that is impossible.

Providing some text that says: "You might want to try right-clicking on this link, and choose "save target as" in the context menu to save this file"
seems to be a better solution.

--
http://home.mysth.be/~timvw

That I understand, I have tried that, but sometimes, people dont get it, and
sometimes there on a mac, and need to hit apply or ctlr key or something.

it is good to always send correct mime-types, so the browser know what to do
with the file. but if a browser recieves an unknown file type, it tends to
pop a dialog to save file, so this is a great workaround for file saving.

we are both arguing valid points, we are both correct in our own right (i
think that how you spell right in this situation)

(sorry if I was rude earlier, I was dealing with a buch of other questions,
and should not have vented your way, again, my apologies)
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #8

P: n/a
CountScubula wrote:
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:bt************@ID-188825.news.uni-berlin.de...

Providing some text that says: "You might want to try right-clicking on
this link, and choose "save target as" in the context menu to save this
file" seems to be a better solution.
That I understand, I have tried that, but sometimes, people dont get it, and
sometimes there on a mac, and need to hit apply or ctlr key or something.


I don't believe that's a good alternative either. Apart from the risk
of causing confusion, you can't be sure the user has an option "save
target as" in the context menu, or has a right mouse button, or
clicks a mouse button to select something, or uses a mouse, or has a
mouse, and so on ad infinitum. In general, I don't see the point in
any sentence that reads along the same lines as the above one, even a
device-independent one; authors should normally avoid mentioning
mechanics [1] (an important principle).
it is good to always send correct mime-types, so the browser know what to do
with the file.
I agree. But regardless of whether an appropriate content-type value
is given, the browser should always do *something*, e.g., prompt the
user to save the data, invoke a helper or plug-in, or simply present
the data itself.
but if a browser recieves an unknown file type, it tends to pop a dialog to
save file, so this is a great workaround for file saving.


In doing so, however, you're trying to force a particular action upon
the user's browser -- something that cannot be achieved all round,
but might unfortunately "work" in some cases. I don't believe that to
be the best way of serving files. What if, for example, the user
configures their browser to automatically load application/msword
files into Word, or some other application? Your attempt at forcing a
dialogue box to appear may actually succeed, effectively overruling
the user's preferences. You'd also be wasting their time, inasmuch as
they may have one or more dialogue boxes to deal with in order to
access the data.

We already know that there is no way to force, as the FAQs and
previous discussions explain. I see no reason whatsoever to favour a
made-up MIME media type over an appropriate, registered one.
[1] "Avoid talking about mechanisms", Tim BL,
http://www.w3.org/Provider/Style/NoMechanics.html

--
Jock
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.