Page 1 of 1

fopen corrupt file

Posted: Sat Jul 10, 2004 12:52 am
by ShadoFlameX
Hello

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";
}
Any help would be great

Posted: Sat Jul 10, 2004 2:41 am
by kettle_drum
Do you have permission to read in that dir and the file itself? If the file is in the directory below the script that you can just reference it with "pdf/file.pdf";

Try to place the file name into a string first and then echo it out to make sure everything is ok.

Posted: Sat Jul 10, 2004 4:18 am
by ShadoFlameX
Yes, there was a minor problem with the file path afterall, however, I had disabled display errors and with this off the file was downloading and then trying to open. For some reason a lot of binary data (78k) was getting DLed which led to the confusion. Thanks for the help tho, Cheers