PHP - download multiple text files by submitting an htmlform

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default PHP - download multiple text files by submitting an htmlform

    Hello,

    I am building a site that allows the user to download a set of text files
    based on user selection on HTML forms. For example, the user can choose to
    download data starting from year1 = 2005, month1 = Jan, day1 = 1 until
    year2 = 2005, month2 = Jan, day2 = 5 (totalling 5 days of data)

    I can only get the program to download one text file with all the 5 sets of
    data appended to the same text file when the form gets submitted. What I
    actually want is to get PHP to download "multiple" and separate text files once
    the form get submitted.

    I tried to do this for each set of data in the same php script:

    $fname = "fileA";

    header("Content-Disposition: attachment; filename=$fname", false);

    echo $file_contentA;

    $fname = "fileB";

    header("Content-Disposition: attachment; filename=$fname", false);

    echo $file_contentB;

    ...same thing for fileC, fileD, and file E


    I tried to have multiple of these headers and printing the file contents in
    different places throughout the program hoping to get downloads of multiple
    files.

    PHP is recognizing only one headers at a time (i.e. only downloads 1 file at a
    time). Thus, all the "echo filecontent" statements go into the same destination
    file.

    How can I have downloads of multiple files? so that filecontent A, B, C, D, E
    can be 5 separate files when downloaded? is it possible to download more than 1
    file at a time?

    Question2:
    If it is only possible to download 1 file at a time, how can I "create" 5
    files, get them zipped, and let the user download that product zip file?
    I could not find any "create zip file" functions through php.net and
    phpbuilder.com

    Thanks a lot!

    Stanton

    StantonWeb Guest

  2. Similar Questions and Discussions

    1. Multiple emails when submitting a form?
      Does anyone know whether or not you can have a form submit to multiple email address' when you submit a form? Especially when you distribute the...
    2. Multiple files download?
      Originally posted by: 2JZ Hi all, I am using FileReference's download() to download file. However, it seems that donwload() only donwload one...
    3. Loading Multiple Text files
      Hi! I've got several archived text files - 040107.txt, 040207.txt, 040307.txt, for example - and I want to be able to build a dynamic link which...
    4. Submitting data from single tab using multiple tab form
      I have a flash form with multiple tabs. When a submit button is pressed, however, I would like only the information from the current tab to go to...
    5. Submitting multiple record IDs via a form.
      I have a problem more to do with style than ability; I can solve this problem in a number of ways, but I'm keen to find the best way of doing...
  3. #2

    Default Re: PHP - download multiple text files by submitting an html form

    .oO(StantonWeb)
    >PHP is recognizing only one headers at a time (i.e. only downloads 1 file at a
    >time). Thus, all the "echo filecontent" statements go into the same destination
    >file.
    That's how HTTP works: First the headers, then the content. You can't
    send additional headers after the content has been sent. PHP will
    complain about that with a warning unless you use output buffering.
    >How can I have downloads of multiple files? so that filecontent A, B, C, D, E
    >can be 5 separate files when downloaded? is it possible to download more than 1
    >file at a time?
    No. One request, one response.
    > Question2:
    > If it is only possible to download 1 file at a time, how can I "create" 5
    >files, get them zipped, and let the user download that product zip file?
    > I could not find any "create zip file" functions through php.net and
    >phpbuilder.com
    PHP is capable of reading and writing .gz files, at least WinZip is able
    to decompress them.

    CXL. Zlib Compression Functions
    [url]http://www.php.net/manual/en/ref.zlib.php[/url]

    Another way would be to use an external program on the server to create
    the archive, but this depends on the server and the installed software.
    On a *nix machine it should be possible.

    Micha
    Michael Fesser Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139