Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Location
    UK
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post

    linking to a pdf file

    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?

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,371
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Location
    UK
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post
    Here it is,

    Code:
     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;	
    ?>

  • #4
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,371
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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;

    }

  • #5
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    I Guess You Using small code to display your file name in directory... e.g.
    PHP Code:
    $OpenFileName=opendir("yourfilename.pdf"); // or *.pdf
    while (($file readdir($OpenFileName))!==false) {
    echo 
    "$file <br>";
    }
    closedir($OpenFileName); 
    Hope it can help you..
    Best Regards,

  • #6
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    If you don't sure, I guess you use small code like:
    PHP Code:
    $OpenFileName=opendir(".");
    while ((
    $file readdir($OpenFileName))!==false) {
    echo 
    "$file <br>";
    }
    closedir($OpenFileName); 
    to browser you filename in your directory
    hope this can help you
    Best Regards,

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Location
    UK
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by mlseim View Post
    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

  • #8
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,371
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    Is it just the filename, like "mypdffile.pdf",

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

  • #9
    Regular Coder
    Join Date
    Feb 2003
    Location
    UK
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post
    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

  • #10
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,371
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    On these lines:
    array(".pdf","application/pdf",0),

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

  • #11
    Regular Coder
    Join Date
    Feb 2003
    Location
    UK
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by mlseim View Post
    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.

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,371
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •