LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2010, 02:36 AM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Php and (pdf) file sending by http


I have a web page that has links to a php script that sends pdf files to the browser when clicked.
The links are like this:
Code:
<a href="getfile.php?id=1201234">
The files sent are shown embedded in the browser, which is what I want.

The problem is: the title of the browser window or tab in which the pdf file is opened is "getfile.php?id=1201234"), and not the actual file name of the pdf file.

Is it possible to send the file by a php script in a way that the window/tab title becomes the filename and not the link by which it has been accessed?

Last edited by J_Szucs; 12-09-2010 at 02:38 AM.
 
Old 12-09-2010, 01:32 PM   #2
barriehie
Member
 
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
Quote:
Originally Posted by J_Szucs View Post
I have a web page that has links to a php script that sends pdf files to the browser when clicked.
The links are like this:
Code:
<a href="getfile.php?id=1201234">
The files sent are shown embedded in the browser, which is what I want.

The problem is: the title of the browser window or tab in which the pdf file is opened is "getfile.php?id=1201234"), and not the actual file name of the pdf file.

Is it possible to send the file by a php script in a way that the window/tab title becomes the filename and not the link by which it has been accessed?
Code:
<a href="getfile.php?id=1201234" title="some_title">
 
1 members found this post helpful.
Old 12-09-2010, 02:40 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Very nice solution. Thanks for posting it.
 
Old 12-09-2010, 02:44 PM   #4
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
Thank you, it is really a nice solution, but, since a pdf is not html content, it might not work.

I think I have tried that the first time, and failed with both firefox and ie. Just to be sure, I will recheck it tommorrow.

I think, however, that I have just figured out an other solution using apache mod_rewrite to trick the browser (or the embedded acrobat reader?):

Links should be formed like:
"/files/<file id>/<filename>.pdf"
and the browsers (or acrobat reader?) would be happy to put <filename>.pdf into the window title.

The php script would not be that happy with that request, actually, it would not even see it, but here Apache could help by rewriting it to:
"/getdoc.php?id=<file id>"
and the php script would now be glad to serve the file based on the file id.

This rewrite rule might do the trick, I suppose:
"RewriteRule ^/files/([^/]+)/[^/]+.pdf$ /getdoc.php?id=$1"

I know, it is a really ugly solution, but it might work. I will also try it tommorrow.

Last edited by J_Szucs; 12-09-2010 at 04:19 PM.
 
Old 12-10-2010, 01:52 AM   #5
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
It looks like browsers do not respect beauty (or the sense of beauty of "gurus"), because the "<a ... title=..>" thingy does not work .

However, the rewrite thingy works like a charm.

Thank you for your attention.

Edit:
Well, actually, it turned out that there is much room for improvement.
I have just noticed that $_SERVER['REMOTE_USER'], $_SERVER['AUTH_USER'], $_SERVER['LOGIN_USER'] and such environment variables are sometimes all empty in the getdoc php script when using mod_rewrite. For some pdf's they are empty, for others, they are not. And I cannot figure out what makes the difference.
So environment variable $_SERVER['SUCKING_DEVELOPER'] is presently filled with my name, as a consequence of not being able to use ntlm_auth along with mod_rewrite reliably.

Last edited by J_Szucs; 12-10-2010 at 05:40 AM.
 
Old 12-10-2010, 09:16 AM   #6
barriehie
Member
 
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
Hmm, html/browser wise the title= thing should've worked; but what does and what is on computers...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP FILE MANAGER (ftp,http download) - suggestions dlugasx Linux - Software 1 10-20-2010 11:38 PM
Sending PDF files in Gambas MGE Programming 2 03-25-2009 02:44 PM
http file sending with c or scripting mattsoftnet Programming 3 01-12-2008 01:51 PM
how i can view the file list available on server side through sending HTTP request? ankuraggarwal Linux - Software 1 09-06-2007 05:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration