RE: Problems downloading a PDF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Mário Gamito [mailto:mgamito@xxxxxxxxx]
> Sent: Wednesday, April 04, 2007 1:46 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Problems downloading a PDF
> 
> Hi,
> 
> I'm building this site that has several PDFs to download, but only to
> registered users.
> 
> To prevent people to insert the full URL to the documents, i moved them
> outside Apache's DocumentRooot, which is /var/www.
> 
> My site is in /var/www/telbit and i put the PDFs in /var/www
> 
> I've coded in order to do the trick, but it's failing.
> I can't get the name of the file.
> Notice that the page which has the code is products-teststudio.php itself.
> 
> The code follows my signature.
> 
> Any help would be appreciated.
> 
> Warm Regards
> --
> :wq! Mário Gamito
> --
> 
> <?php
>   if (isset($_SESSION['email'])) {
>    echo"<a href=\"products-teststudio.php?file=testudio.pdf\"
> rel=\"external\">Download TESTUDIO flyer</a>";
> 
>    $file = $_GET['file'];
> 
>    // try to sanitize the filename
>    if (preg_match('/[^A-Za-z0-9._]/', $file))
>     die("Invalid filename.");
> 
>    $path = '/var/www/';
>    $full = $path . $file;
> 
>    header('Content-type: application/pdf');
>    header("Content-Length: " . filesize($full));
>    header('Content-disposition: attachment; filename="'. basename($file)
> .'"');
>    readfile($full);
>   }
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
[Peter Lauri - DWS Asia] 

You are echoing stuff before sending the file that is not possible. So
remove the echo and it should work. If not, try this for debugging:

if(!is_readable($full)) echo "the file $full is not readable by apache";
else {
	//same as before
}

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux