A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35

Thread: PDF download

  1. #21
    Member
    Join Date
    Aug 2006
    Posts
    49
    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?

  2. #22
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    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.

  3. #23
    Member
    Join Date
    Aug 2006
    Posts
    49
    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!

  4. #24
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    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.

  5. #25
    Member
    Join Date
    Aug 2006
    Posts
    49
    Quote 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

  6. #26
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    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.

  7. #27
    Member
    Join Date
    Aug 2006
    Posts
    49
    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?

  8. #28
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    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.

  9. #29
    Member
    Join Date
    Aug 2006
    Posts
    49
    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..

  10. #30
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    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.

  11. #31
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    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

  12. #32
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    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.

  13. #33
    Member
    Join Date
    Aug 2006
    Posts
    49
    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%

  14. #34
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    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

  15. #35
    Member
    Join Date
    Aug 2006
    Posts
    49
    Quote 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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center