473,394 Members | 1,714 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,394 software developers and data experts.

Want to make a link anchor call a PHP script

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
8 4289
"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
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
"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
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
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: deko | last post by:
Is it possible to call a php script from an html page? I have a TestPage.php that I want to convert to TestPage.html - but still call a php script from it. This is how my TestPage.php looks...
4
by: Jerry Sievers | last post by:
JS Programmers, "I'm a server-side coder PHP, Postgres etc... My question; Given the following anchor <a href="http://www.somesite.com/somefile.html">link text</a> Is there a way to code an...
0
by: John Smith | last post by:
How to make link button in a data grid non hyperlink at runtime. Depending upon the data in the cell I would like to make it hyper link or non-hyper link. I am reading the data in the item data...
3
by: zaeminkr | last post by:
I have class member data which is a pointer to class member function. However, I'm fail to compile the code. What is the correct grammar to make a function call by using static member data...
0
by: atulsharma84 | last post by:
i want to write a python script for a device NGX-5500 whose vendor is telllabs i hv to write python file like some other device file i m giving u example here below import java.lang as lang...
0
by: raaja | last post by:
wats the script tat how to make link one flash button to .vb in local host?
1
by: Rabiya | last post by:
hi, i want to have the perl script that can take input from any text file. i have the one bt its not doing the required job
3
by: Noorain | last post by:
i use .Net Crystal Report to create reports. now i want to link this report with php script. how it is possible. Please help me. Thanks
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.