Jump to content

[SOLVED] Download generated file...


yungbloodreborn

Recommended Posts

I would like to generate a file, and give it a name for a download.

 

The result would be something like:

 

<a href="http://mysite.com/getfile.php?file=1335">Download Poem</a>

 

When I click that link, I want it to pop up a save as (download) box. I want the name that appears in that box to be whatever I choose. (i.e. 'odephp.txt') And the contents of the file would be generated from a script.

 

<?php
  echo 'Ode to PHP';
  echo '................';
  echo 'Php how do I love thee?';
  echo 'Let me count the ways';
  $max = $_REQUEST['file'];
  $cnt = 0;
  while ($cnt < $max) {
    echo "$cnt...";
    $cnt++;
  }
?>

 

I would imagine that I need some kind of header call, but I'm missing a key piece to make it all work. Can someone please help?

Link to comment
https://forums.phpfreaks.com/topic/111931-solved-download-generated-file/
Share on other sites

Damn, I just found the answer in another post. heh :) The answer wasn't there when I posted the first time... :)

<?php
  header('Content-Disposition: attachment; filename="odephp.txt"');

  printf("Ode to php\n");
  printf("...\n");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.