[PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

2003-09-18 Thread Steve Jackson
I know a few have already done this on the list but I have read articles
on Zend tried other functions done everything I can, de-bugged till I'm
blue in the face and still haven't been able to solve this.

I need to protect files by leaving them outside the web root.
I call them up ok. (the link is get.php?file=EventNotifcation_01.pdf)
I can download the file fine by right clicking the link in the browser
and saving it to disk.
My problem is I can't view it inline. IE in the browser. It's a PDF file
so I should be able to.
This is the code that processes:

? 
// path to file outside of root.
define('FILEDIR', '/home/.sites/144/site281/downloads/'); 
$path = FILEDIR . $file; 
//check that this file exists and that it doesn't include 
//any special characters 
if(!is_file($path) OR !eregi('^[A-Z_0-9][A-Z_0-9.]*$', $file)) 
{ 
header(Location: error.php); 
exit(); 
} 

/* 
** //check that the user has permission to download file 
** if(user does not have permission) 
** { 
** //redirect to error page 
** header(Location: error.php); 
** exit(); 
** } 
*/ 

// get the extension of the file

$p = explode('.', $file);
$extension = $p[sizeof($p)-1];
switch ($extension)
{
// define headers depending on $extension variable.
case pdf :
header(Content-type: application/pdf);
header(Content-disposition: inline;
filename=\.basename($file));
break;
case txt :
header(Content-type: text/plain);
header(Content-disposition: inline;
filename=\.basename($file));
break;
default :
// force download dialog if no extension defined.
header(Content-type: application/octet-stream); 
header(Content-disposition: attachment; filename=\$file\);
break; 
}
header(Content-transfer-encoding: binary); 
  header(Content-length:  . filesize($path));
  header(Cache-control: must-revalidate); 
//send file contents 
  $fp=fopen($path, r); 
fpassthru($fp);
// debug - remove the headers and test output vars. 
/*echo Extension is $extension;
echo brFile is $file;
echo brp is $p;
echo brpath is $path;
echo brFP is $fp;*/
? 

Echoing the vars results in:
Extension is pdf
File is EventNotification_01.pdf
P is Array
Path is /home/.sites/144/site281/downloads/EventNotification_01.pdf
FP is Resource is #1

Has anyone got any clue what the problem is? 


Steve Jackson
Web Development and Marketing Manager
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

2003-09-18 Thread Jason Wong
On Thursday 18 September 2003 16:24, Steve Jackson wrote:
 I know a few have already done this on the list but I have read articles
 on Zend tried other functions done everything I can, de-bugged till I'm
 blue in the face and still haven't been able to solve this.

 I need to protect files by leaving them outside the web root.
 I call them up ok. (the link is get.php?file=EventNotifcation_01.pdf)
 I can download the file fine by right clicking the link in the browser
 and saving it to disk.
 My problem is I can't view it inline. IE in the browser. It's a PDF file
 so I should be able to.

[snip]

Have you tried the obvious, such as using browsers other than IE? Or a 
different version of IE? 

Fact is that there are versions of IE that have broken mime handling.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
modem, adj.:
Up-to-date, new-fangled, as in Thoroughly Modem Millie.  An
unfortunate byproduct of kerning.

[That's sic!]
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

2003-09-18 Thread Steve Jackson
 Have you tried the obvious, such as using browsers other than 
 IE? Or a 
 different version of IE? 
 

So far I've tried IE 6.0.2, IE 5.0, Netscape 7 and they don't work. 

 Fact is that there are versions of IE that have broken mime handling.

This I didn't know, so I just tried it on Konqueror running on Linux and
it works. However where do I go from here? One thing that Konqueror
brought up is that get.php is the filename that it gives the file when
trying to save it. Could that be the problem? Get.php is the name of the
script that passes the file but not the name of the file itself.

Finally a step in the right direction but how do I go about solving
this?
Kind regards
Steve. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

2003-09-18 Thread Steve Jackson
The simple things are the stupidest. One thing I didn't do well enough.
Testing on different machines. I ran numerous tests from my own PC and
numerous tests from a development server using different software. Only
when Jason mentioned Mimetypes did I think about doing more tests on
adifferent machine.
My problem wasn't with the PHP, the server or anything else but with my
fecking version of Adobe Acrobat. After trying to open a different PDF
file I realised my problem. So after a re-boot of my PC everything works
fine.
Thanks for the patience and hope this lesson in my stupidity can help
someone else!


Steve Jackson
Web Development and Marketing Manager
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159





 -Original Message-
 From: Steve Jackson [mailto:[EMAIL PROTECTED] 
 Sent: 18. syyskuuta 2003 12:19
 To: [EMAIL PROTECTED]
 Subject: RE: [PHP] This is my fourth day of hitting this 
 brick wall! Anyone...Purlese help!
 
 
  Have you tried the obvious, such as using browsers other than
  IE? Or a 
  different version of IE? 
  
 
 So far I've tried IE 6.0.2, IE 5.0, Netscape 7 and they don't work. 
 
  Fact is that there are versions of IE that have broken mime 
 handling.
 
 This I didn't know, so I just tried it on Konqueror running 
 on Linux and
 it works. However where do I go from here? One thing that Konqueror
 brought up is that get.php is the filename that it gives the file when
 trying to save it. Could that be the problem? Get.php is the 
 name of the
 script that passes the file but not the name of the file itself.
 
 Finally a step in the right direction but how do I go about solving
 this?
 Kind regards
 Steve. 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

2003-09-18 Thread Jim Lucas
also, here is a good one to try.

build yourself an error document that gets called when a file that cannot
befound is looked for.

Then in this error document, you perform a check on the file/script name
that was called.  If it happens to end with .pdf, then you could assume that
it is going to be a pdf that needs to be displayed.  Then you get the name
of the file called and look for it in your directory that contains all your
pdf's.  If you find a file in there by the same name, then you can use
readfile or some other file reader to pass the file through.

This should take care of the problem.  You might also need to send back some
specific headers to tell the browser what you are sending it, but it should
work even without that being done.

Jim Lucas

- Original Message - 
From: Jason Wong [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, September 18, 2003 2:01 AM
Subject: Re: [PHP] This is my fourth day of hitting this brick wall!
Anyone...Purlese help!


 On Thursday 18 September 2003 16:24, Steve Jackson wrote:
  I know a few have already done this on the list but I have read articles
  on Zend tried other functions done everything I can, de-bugged till I'm
  blue in the face and still haven't been able to solve this.
 
  I need to protect files by leaving them outside the web root.
  I call them up ok. (the link is get.php?file=EventNotifcation_01.pdf)
  I can download the file fine by right clicking the link in the browser
  and saving it to disk.
  My problem is I can't view it inline. IE in the browser. It's a PDF file
  so I should be able to.

 [snip]

 Have you tried the obvious, such as using browsers other than IE? Or a
 different version of IE?

 Fact is that there are versions of IE that have broken mime handling.

 -- 
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-general
 --
 /*
 modem, adj.:
 Up-to-date, new-fangled, as in Thoroughly Modem Millie.  An
 unfortunate byproduct of kerning.

 [That's sic!]
 */

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

2003-09-18 Thread Marek Kilimajer
Jim Lucas wrote:

 This should take care of the problem.  You might also need to send back some
 specific headers to tell the browser what you are sending it, but it should
 work even without that being done.

I think this works only in IE, always send Content-Type.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php