...

View Full Version : linking to a pdf file



TinMan
01-13-2010, 07:08 PM
I have a secure login area where clients can view a price list, this has worked fine in the past, but not anymore.

I have a menu on index.php, one of the options being "view price list"
The price list is in this same directory and is called "PriceList2010".
However this link

<li class="profile-info"><a href="redir.php?filename=PriceList2010.pdf" alt="View Price List" >View Price List</a></li>

now seems unable to open the pdf, so I assume I have made a stupid mistake somewhere, but am not sure where.

can anyone advise please?

mlseim
01-13-2010, 07:19 PM
You have a script called "redir.php" ... where the problem is at ...
But you didn't show us that script.

EDIT: are you sure it's called, "PriceList2010.pdf" and not something like "Pricelist2010.pdf"?
Check caps and small letters.

TinMan
01-15-2010, 11:34 PM
Here it is,


include_once ("../../admin/config.php");

$SUBMIT_FORM_VARS = array_merge($HTTP_POST_VARS,$HTTP_GET_VARS);

if (isset($SUBMIT_FORM_VARS["filename"])){
$filename = $SUBMIT_FORM_VARS["filename"];
}
else{
echo "<meta http-equiv=\"refresh\" content=\"0; URL=$url_root/forbidden.php\">";
exit;
}

$group_num = $_COOKIE['access_num'];
$flag=0;
for ($i=0;$i<$group_num;$i++) {
$gname="access_".$i;
$group = $_COOKIE[$gname];
if ($group==$curgroup) {$flag=1;}
}
if ($flag==0) { //no access to this folder
echo "<meta http-equiv=\"refresh\" content=\"0; URL=$url_root/forbidden.php\">";
exit;
}

$supportedExtensionsArray = array(array(".asf","video/x-ms-asf",1),
array(".asp","text/asp",0),
array(".asx","video/x-ms-asf",1),
array(".au","audio/basic",1),
array(".avi","video/avi",1),
array(".bm","image/bmp",0),
array(".bmp","image/bmp",0),
array(".css","text/css",0),
array(".doc","application/msword",1),
array(".eps","application/postscript",1),
array(".exe","application/octet-stream",1),
array(".gif","image/gif",0),
array(".gz","application/x-gzip",1),
array(".gzip","application/x-gzip",1),
array(".htm","text/html",0),
array(".html","text/html",0),
array(".htmls","text/html",0),
array(".ico","image/x-icon",0),
array(".jpe","image/jpeg",0),
array(".jpeg","image/jpeg",0),
array(".jpg","image/jpeg",0),
array(".js","application/x-javascript",1),
array(".lsp","application/x-lisp",1),
array(".mid","audio/midi",1),
array(".midi","audio/midi",1),
array(".mod","audio/mod",1),
array(".mov","video/quicktime",1),
array(".mp3","audio/mpeg3",1),
array(".mp3","video/mpeg",1),
array(".mpeg","video/mpeg",1),
array(".mpg","audio/mpeg",1),
array(".mpg","video/mpeg",1),
array(".pdf","application/pdf",0),
array(".pic","image/pict",0),
array(".pict","image/pict",0),
array(".pl","text/plain",0),
array(".png","image/png",0),
array(".ppt","application/mspowerpoint",1),
array(".ppt","application/powerpoint",1),
array(".ps","application/postscript",1),
array(".psd","application/octet-stream",1),
array(".qt","video/quicktime",1),
array(".ra","audio/x-realaudio",1),
array(".ram","audio/x-pn-realaudio",1),
array(".rm","audio/x-pn-realaudio",1),
array(".rmi","audio/mid",1),
array(".rtf","text/richtext",1),
array(".shtml","text/html",0),
array(".shtml","text/x-server-parsed-html",0),
array(".swf","application/x-shockwave-flash",1),
array(".text","text/plain",0),
array(".tgz","application/x-compressed",1),
array(".tif","image/tiff",0),
array(".tiff","image/tiff",0),
array(".txt","text/plain",0),
array(".vsd","application/x-visio",1),
array(".wav","audio/wav",1),
array(".word","application/msword",1),
array(".wp","application/wordperfect",1),
array(".wri","application/mswrite",1),
array(".xls","application/excel",1),
array(".xml","text/xml",0),
array(".zip","application/zip",1));

for ($i=0; $i<count($supportedExtensionsArray); $i++){

$extension = $supportedExtensionsArray[$i][0];
$contentType = $supportedExtensionsArray[$i][1];
$download = $supportedExtensionsArray[$i][2];

$extensionLength = strlen($extension);
$fileExtension = substr($filename,
(strlen($filename) - $extensionLength),
strlen($extension));

if (strtolower($fileExtension) == $extension &&
file_exists($filename)){

header("Content-type: " . $contentType);

if ($download){
header("Content-Disposition: attachment; filename=" . $filename);
}
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

readfile($filename);
//echo file_get_contents($filename);
exit();
}
}
echo "<meta http-equiv=\"refresh\" content=\"0; URL=$url_root/forbidden.php\">";
exit;
?>

mlseim
01-16-2010, 02:14 AM
Insert the part in red into this portion, and see what the $filename is ...
I'm thinking the path to your PDF file is wrong. It checks for the existence
of the file, but it also needs to know the path to the file.

if (isset($SUBMIT_FORM_VARS["filename"])){
$filename = $SUBMIT_FORM_VARS["filename"];
echo $filename;
exit;
}

sir.jones
01-16-2010, 08:12 PM
I Guess You Using small code to display your file name in directory... e.g.

$OpenFileName=opendir("yourfilename.pdf"); // or *.pdf
while (($file = readdir($OpenFileName))!==false) {
echo "$file <br>";
}
closedir($OpenFileName);
Hope it can help you..

sir.jones
01-16-2010, 08:15 PM
If you don't sure, I guess you use small code like:

$OpenFileName=opendir(".");
while (($file = readdir($OpenFileName))!==false) {
echo "$file <br>";
}
closedir($OpenFileName); to browser you filename in your directory
hope this can help you

TinMan
01-19-2010, 05:03 PM
Insert the part in red into this portion, and see what the $filename is ...
I'm thinking the path to your PDF file is wrong. It checks for the existence
of the file, but it also needs to know the path to the file.

if (isset($SUBMIT_FORM_VARS["filename"])){
$filename = $SUBMIT_FORM_VARS["filename"];
echo $filename;
exit;
}

This does come back with the correct file name

mlseim
01-19-2010, 07:14 PM
Is it just the filename, like "mypdffile.pdf",

or the path and filename?
Like this: files/pdf/mypdffile.pdf

TinMan
01-19-2010, 08:01 PM
just the filename,

What seems to come up wether I try to view or download the pdf is a lot of coding or mumbo jumbo that opens in notepad.
PDF files are not configured to open in notepad.

What I cannot understand is that this used to work fine

mlseim
01-19-2010, 09:20 PM
On these lines:
array(".pdf","application/pdf",0),

Do you know what the ,0 and ,1 means?

TinMan
01-19-2010, 11:19 PM
On these lines:
array(".pdf","application/pdf",0),

Do you know what the ,0 and ,1 means?

As I didnt write the script, no I dont.

_Aerospace_Eng_
01-20-2010, 01:31 AM
At a quick glance the 0 or 1 specifies on whether or not to download that content-type so if its 0 it shouldn't generate a download. If a 1 then it should put out the proper headers.

mlseim
01-20-2010, 01:22 PM
At a quick glance the 0 or 1 specifies on whether or not to download that content-type so if its 0 it shouldn't generate a download. If a 1 then it should put out the proper headers.

That's what I thought.
Make that a "1" and maybe it will work?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum