I am trying to get a script to download files from a "hidden" location working. My problem is that if the file I want to fopen is located in a directory other than where this script php file is located I get a corrupted file which will not open. For instance if I change "$fp2 = fopen("/Users/smith/Sites/main/vSignup_2/".$filename, 'rb');" to "$fp2 = fopen("/Users/smith/Sites/main/vSignup_2/pdf/".$filename, 'rb');" then it will not work. (Yes I have the file in the right location for each instance) My code is as follows:
Code: Select all
if ($_GETї"id"]) {
$pdfID = $_GETї"id"];
$userID = $checkї"id"];
$result = mysql_query(" SELECT pdfName, pdfLoc
FROM pdffile INNER JOIN pdfpurchase ON pdffile.id = pdfpurchase.pdffileID
WHERE pdfpurchase.authuserID='$userID' AND pdfpurchase.pdffileID='$pdfID' ");
$row = mysql_fetch_array($result);
if ($row != NULL) {
$filename = $rowї'pdfLoc'];
header("Content-type: application/octet-stream");
header("Content-Length: ".filesize($filename));
header("Content-Disposition: attachment; filename=$filename");
$fp2 = fopen("/Users/smith/Sites/main/vSignup_2/".$filename, 'rb');
fpassthru($fp2);
fclose($fp2);
}
else {
echo "No MySQL row returned";
}
}
else {
echo "Page entered w/o ID num";
}