-
Neither of the two you mentioned are getting it to download the PDF. It's still trying to download the php file.
Yes, my rootfolder for my website is www.mysite.com on the C:// drive. Does this cause complications?
-
FK's Official Mac Hater
No problems there. I have something for you to try. Download the PHP file and open it. Does it contain some kind of error? If it contains your PHP code then your server A) Doesn't have PHP installed or B) Doesn't have PHP configured.
Jason L. Wright
I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.
-
It contains the PHP code.. My father is hosting my site on his server.. However, I've been testing this locally. Would that cause this sort of error? Should I upload it to the server and then try it?
I just uploaded the site to the server and recieved this error message:
Parse error: parse error, unexpected T_STRING in /var/www/www.mysite.com/downloadpage.php on line 3
*www.mysite.com is just a fill in for actual site name, which I would rather not divulge for privacy concerns. Thanks for your help!
-
FK's Official Mac Hater
In order for this to work it must be passed through a PHP interpretor meaning that it needs to be on a server where PHP is enabled. If you are using my first example you should be getting that error because I left one of the quote marks off. Here it is fixed:
Code:
<?php
$file = "resume.pdf";
if($fp = fopen("/var/www/www.mysite.com/", "r"))
{ header("Content-type: application/download"); // also possible: application/octet-stream, unknown/unknown
header("Content-disposition: attachment; filename=\"$file\"");
fpassthru($fp);
}
else
{ header("HTTP/1.0 404 Not found");
print "$file is not available for downloading":
}
?>
Jason L. Wright
I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.
-
Originally Posted by jasonsplace
In order for this to work it must be passed through a PHP interpretor meaning that it needs to be on a server where PHP is enabled. If you are using my first example you should be getting that error because I left one of the quote marks off. Here it is fixed:
Code:
<?php
$file = "resume.pdf";
if($fp = fopen("/var/www/www.mysite.com/", "r"))
{ header("Content-type: application/download"); // also possible: application/octet-stream, unknown/unknown
header("Content-disposition: attachment; filename=\"$file\"");
fpassthru($fp);
}
else
{ header("HTTP/1.0 404 Not found");
print "$file is not available for downloading":
}
?>
I used the new code and I am still receiving an error message:
Parse error: parse error, unexpected ':' in /var/www/www.mysite.com/downloadpage.php on line 10
-
FK's Official Mac Hater
Line 10 has a colon at the end...it needs to be a semi-colon.
Jason L. Wright
I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.
-
Just when you think your problems are solved, a new one pop's up.
Jasonplace, thanks so much for your help. Yes, that solved everything. However now, when I download the PDF document, and open it, a new error message appears.
Acrobat could not open 'Resume.pdf' because it is either not a supported file type or because the file had been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
To create an Adobe PDF document, go to the source application. Then Print the document to Adobe PDF.
That's all good what have you, but I know the resume.pdf is legit. because that's exactly how I made it through Indesign....
Do you know what may be causing this New problem?
-
FK's Official Mac Hater
What is the size of the new file compared to the original on the server? If they are the same then it should work. If the downloaded one is a lot smaller then open it in Notepad and see if it lookks weird or contains any clues.
Jason L. Wright
I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.
-
They are the exact same size.
However when I open the dowloaded PDF in notepad, it's blank.
when I open up the original file on my computer, it's got all sorts of junk/special characters etc..
-
FK's Official Mac Hater
That can't be right. If the file is bigger than 0 bytes and you open it in Notepad there has to be something in it. Try clearing your cache and downloading the file again.
Jason L. Wright
I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.
-
Hi,
if you are trying this on a windows server, you could try to change "r" file mode into "rb"
What toolare you using to determine they are "exactly the same size" - something like explorer that rounds to kbytes or Mbytes, or the dir command in a dos box that shows results precise to the byte?
If the php code is followed by one or more blank lines, these would appear at the end of the pdf and cause a message like the one you showed
Musicman
-
FK's Official Mac Hater
From his path "/var/www/www.mysite.com/" I assume that he's using a Linux server.
Jason L. Wright
I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.
-
yea, I checked the file size after downloading, it's reading up as 0kb.
Musicman, I also tried chaning "r" to "rb" that does not work either. It seems to be downloading the resume.pdf but it contains no info or size for that matter.
The original file size is 55Kb not sure what the server is. I believe it's windows based. not 100%
-
Hi,
you mentioned that you tried on your own machine (as a test server) and on the real server. The real one is running linux or some other unix-style system and does not need the "rb" - running without it on windows would generate a size discrepance of about 0.5%
However, something has got lost here:
if($fp = fopen("/var/www/www.mysite.com/$file", "r"))
Also, you could use relative path
if($fp = fopen("./$file", "r")) // if it is in the same folder
if($fp = fopen("data/$file", "r")) // if it is in a "data" folder within your web site
Musicman
Musicman
-
Originally Posted by Musicman
Hi,
you mentioned that you tried on your own machine (as a test server) and on the real server. The real one is running linux or some other unix-style system and does not need the "rb" - running without it on windows would generate a size discrepance of about 0.5%
However, something has got lost here:
if($fp = fopen("/var/www/www.mysite.com/$file", "r"))
Also, you could use relative path
if($fp = fopen("./$file", "r")) // if it is in the same folder
if($fp = fopen("data/$file", "r")) // if it is in a "data" folder within your web site
Musicman
Musicman
Musicman & Jasonplace. Thank you both so much for all your help and prompt replies!
Musicman, I followed what you said, and replaced that line of code with:
if($fp = fopen("./$file", "r"))
It's working properly and functional. Thanks again for all your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|