You are here: Re: Opening a pdf file « All PHP « IT news, forums, messages
Re: Opening a pdf file

Posted by Markus Ernst on 06/01/06 07:29

Ozz schrieb:
> Hi there,
> I have a link on my web page. When clicked, opens up a pdf file that is
> stored on my server. Every file is specific to a user's user name and I
> don't want users to see each other's files.
> For example:
> When User1 clicks on the link, it opens up
> http://mydomain.com/files/user1.pdf
> and when User2 clicks on the link, it opens up
> http://mydomain.com/files/user2.pdf.
>
> So, if User1 knows about User2, he can see User2's pdf file.
>
> How can I make the file open up in a different window without the file
> path in the address bar?

You ask a wrong question; the question is: "how can I prevent users from
seeing other users' files". There are several possible solutions for
this; you could deliver the PDF via PHP (using readfile() and header()),
anyway this usually makes problems in Internet Explorer.

In your case I suggest to write a PHP script that copies the PDF to a
temp folder and uses the session id (if your user is logged in and has a
session... otherwise use a random string) as the filename, and outputs a
link to that one. You will then need to add some functionality that
deletes PDFs that are older than some days from the temp folder.

<?php
session_start();
$userfile = $_SERVER['DOCUMENT_ROOT'].'/files/user1.pdf';
$tempname = strip_tags(SID).'.pdf';
$tempfile = $_SERVER['DOCUMENT_ROOT'].'/temp/'.$tempname;
if (copy($userfile, $tempfile)) {
echo '<a href="/temp/'.$tempname.'">Download!</a>';
}
else {
echo 'Sorry, there is a problem with your file!';
}
?>

Not tested!
HTH
Markus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация