Log in

View Full Version : why isn't the following working?



mmq2009
04-24-2009, 10:49 AM
hi ppl,
cant figure out why the following isn't working, im trying to let a user download a file only once, now the download file message comes up but the pdf reader say's its corrupt/illegal...please help

Script 1:


<?php
include( "class.DatabaseConnect.php" );
session_start( );


$check=$_GET['des'];

$dbConn = new DatabaseConnect( );
$dbConn->connect( "workdb" );
$sqlResult8 =
$dbConn->executeQuery("select downloaded from design_tbl where pdf_path='$check'");
$temp8= mysql_fetch_array($sqlResult8);
$pdf=$temp8['downloaded'];

if($pdf==0)
{
sqlResult9 =
dbConn->executeQuery("update design_tbl set downloaded=1 where pdf_path='$check'");

$file = $_GET['file'];
header('location:getit.php?f='.$file.'');
}

if($pdf==1)
{
echo "File already downloaded, contact system admin";

}
?>

second script the above script redirects to:


<?php
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=mydesign.pdf');
readfile($_GET['f']);
?>

borris83
04-24-2009, 11:34 AM
Your script is fine.. But I think the problem is with the file name....

Try echoing $file or just look at the url and see what it says after file=

This file should exist in the same folder where your second script getit.php is stored...

Even if the file doesn't exist, it will still download an unreadable pdf file, and if you open that file in a notepad, you will see a php error in the format given below:

<br />
<b>Warning</b>: readfile(filename.pdf) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>[name of the php file]</b> on line <b>4</b><br />

mmq2009
04-24-2009, 02:44 PM
Your script is fine.. But I think the problem is with the file name....

Try echoing $file or just look at the url and see what it says after file=

This file should exist in the same folder where your second script getit.php is stored...

Even if the file doesn't exist, it will still download an unreadable pdf file, and if you open that file in a notepad, you will see a php error in the format given below:

<br />
<b>Warning</b>: readfile(filename.pdf) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>[name of the php file]</b> on line <b>4</b><br />

thanks,
tried that and get the following:


<br />
<b>Warning</b>: readfile(a***e.o*****k.co.uk/users/3/designs/1239024562.pdf) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>/usr/home/n****e/public_html/clients/o*****k/a****e/getit.php</b> on line <b>5</b><br />

why is this so? i know the file exists (i've *** out the url for dataprotection reasons :rolleyes: )

and why is it giving me two different URL's?, the first one is what get's given to the $file... the directory structure is as so:

http://acme.onlineartwork.co.uk/images/error.png

do i need to code the $file URL differently?

borris83
04-24-2009, 03:25 PM
try saving the file in this directory:

/usr/home/n****e/public_html/clients/o*****k/a****e/

Because this is where the php script is looking for the file...