A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 35

Thread: PDF download

  1. #1
    Member
    Join Date
    Aug 2006
    Posts
    49

    PDF download

    I've searched through the boards, and have been unable to find any threads..

    I apologize if there is one, I just have not seen it.


    I would like to create a download/save button inside of flash.

    This way, once you click it, you are given the option to save a PDF file onto your computer.

    I know you could use the getURL command to link to PDF page, and from there you have the option of saving the PDF, however I am inquring about a process that would elimante that step. In conclusion, here is what I am looking for::



    1. User clicks on Resume button inside flash file/site.
    2. User is now viewing Resume inside of flash file/site.
    3. User decides to dl Resume for filing
    4. User clicks download button
    4a. User is brought to another "PDF web page"
    4b. User can save PDF through web browser.

    5. User saves PDF file onto computer.


    I would like to elimate setps 4a. and 4b.

    Thanks!

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    best practice seems to be getURL('download.php') where download.php just sends a content-type like application/download, a content-disposition attachment with suggested filename, and then actual data

    Musicman

  3. #3
    Member
    Join Date
    Aug 2006
    Posts
    49
    Quote Originally Posted by Musicman
    Hi,

    best practice seems to be getURL('download.php') where download.php just sends a content-type like application/download, a content-disposition attachment with suggested filename, and then actual data

    Musicman

    Thanks for the reply.

    I am also new to PHP. So does the server hosting the site need to have php? I don't think it does. Can you create a php document in dreamweaver?

    You said to use ----getURL('download.php'), is the 'download.php' the actual document that will be downloaded, or is it just the *.php document that will be called upon to supply the file to be downloaded. If so, does the actual file (in this case *.PDF file) need to be embedded with in the *.php file?

  4. #4
    associate admedia's Avatar
    Join Date
    Oct 2001
    Location
    is
    Posts
    1,347
    Quote Originally Posted by elanio
    Thanks for the reply.

    I am also new to PHP. So does the server hosting the site need to have php? I don't think it does.
    Yes, and it should. Most web servers support php.

    Quote Originally Posted by elanio
    Can you create a php document in dreamweaver?
    Yes most definitely... but use code view, not layout view.
    There is example of doing just what you are asking here
    PHP Code:
    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');

    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');

    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>
    http://us2.php.net/header

  5. #5
    Member
    Join Date
    Aug 2006
    Posts
    49
    admedia... Thanks for the reply. I just need a bit of clarification.

    Here is the code I creadted for the *.php file in dreamweaver

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');

    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');

    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>
    </body>
    </html>


    Inside of flash, the actionscripting that is associated with the download button is as follows:

    on (release) {
    getURL("downloaded.PDF", "_blank");
    }


    Is this all correct? I know I am missing a step and have tried troubleshooting and searching other forums.

    Thanks for all the help

  6. #6
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    The entire PHP document will be:
    Code:
    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');
    
    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');
    
    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>
    You don't ned the body, html, head or any other tags. Only the stuff that is in my code block.
    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. #7
    Member
    Join Date
    Aug 2006
    Posts
    49
    Quote Originally Posted by jasonsplace
    The entire PHP document will be:
    Code:
    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');
    
    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');
    
    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>
    You don't ned the body, html, head or any other tags. Only the stuff that is in my code block.

    Jason.. Thanks for all the help.. However, I am still having quirks.

    Inside of my flash file, the link to download works.
    However, when I click the link, I am prompted, with the option of saving the .PHP document which is named downloaded.php.


    this is the downloaded.php document and it's coding in its entirety.
    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');

    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="resume.pdf"');

    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>


    The link within flash contains this code only.
    on (release) {
    getURL("download.php", "_blank");
    }


    I'm sure I sound like a newbie, but I am. Thank you all for your patience, and help!

  8. #8
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    maybe your browser gets this wrong - it should prompt to save as resume.pdf
    Give it a try without the "double quotes" around the file name

    Musicman

  9. #9
    Member
    Join Date
    Aug 2006
    Posts
    49
    Musicman.. I tried that.

    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');

    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename=resume.pdf');

    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>


    I took out the dbl. quotes.
    when I click the link, I am givin this message

    File not found













    Firefox can't find the file at /C:/www.mysite.com/download.php/resume.pdf.

    * Check the file name for capitalization or other typing errors.

    * Check to see if the file was moved, renamed or deleted.

  10. #10
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    The double quotes are optional. I'de leave them in because it looks more organized to me but it isn't necessary. Is there a file called original.pdf on your server? or are you just using it because it was in the example?
    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. #11
    Member
    Join Date
    Aug 2006
    Posts
    49
    because it was in the example, I thought it was part of an identifier.

  12. #12
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    You want to replace original.pdf with the name of the PDF file that is on your server. If it can't load the PDF specified there then it won't be able to pass it on to the end user.
    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. #13
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    I am routinely using this - slightly different - script.
    [code]
    <?
    $file = "resume.pdf";
    if($fp = fopen("/path/to/$file", "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":
    }
    ?>
    [code]

    I am pretty sure that I read something about a problem with those quotes, but it was probably with an ancient browser version

    Suggestion: in the flash part, try to omit the "_blank" part entirely - at least on my system this avoids opening a blank browser window in addition to the download

    Musicman

  14. #14
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    The quotes don't work with IE 4...if someone is still using IE 4 then they don't deserve your file.
    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.

  15. #15
    Member
    Join Date
    Aug 2006
    Posts
    49
    when it does work, and it has, It is not downloading the pdf document, instead, it is downloading the php file.

  16. #16
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    It would be downloading the PHP file when it can't find the PDF document that the PHP file is looking for.
    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.

  17. #17
    Member
    Join Date
    Aug 2006
    Posts
    49
    That does not make sense then. if this code is coded correctly, and the pdf document is in the same folder as the php document, then why wouldn't it download the .PDF?

    I am getting confused with some of the coding that has been posted, mainly confused about which part I subsititue the name of the document for.

    So in this code:

    [code]
    <?
    $file = "resume.pdf";
    if($fp = fopen("/path/to/$file", "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":
    }
    ?>
    [code]

    are the parts in dark red, the parts which I subsitute the file path/names?

  18. #18
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    Yes. You will leave this line alone:
    header("Content-disposition: attachment; filename=\"$file\"");
    but the 2 first red lines will have to be substituted with the filename and the path to your directory.
    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.

  19. #19
    Member
    Join Date
    Aug 2006
    Posts
    49
    nope.. Even after I did that, I am still prompted to save the "download.php" file instead of the "resume.pdf" file. Thoughts suggestions? Is this a server side problem, or is it my coding?

    Here is what I used:

    [code]
    <?
    $file = "resume.pdf";
    if($fp = fopen("C:\www.mysite.com/resume.pdf", "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":
    }
    ?>
    [code]

  20. #20
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    Use either

    Code:
    <?php
    $file = "resume.pdf";
    if($fp = fopen("C:/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":
    }
    ?>
    or:
    Code:
    <?php
    $file = "resume.pdf";
    if($fp = fopen("C:\\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":
    }
    ?>
    You don't want the filename in the path variable as they are later attached. When you use a forward slash in a string you have to put 2 of them as it is used to escape characters. Alternately, you can use 1 forward slash.

    Also, is your folder really called www.mysite.com in the root of your C drive?
    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.

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