Solved

Send long string as aparameter

Posted on 2004-09-28
7
313 Views
Last Modified: 2012-06-21
In my php/html application, I need to let the user download an xls file I have stored in $xls string.

I thought to do this way:

if (isset($_GET['download']) && $_GET['download']==true) {
            header("Content-type: application/octet-stream");
            header("Content-Disposition: attachment; filename=extraction.xls");
            header("Pragma: no-cache");
            header("Expires: 0");
            print "$header\n$xls";
            }
            
      echo "<a href=\"{$_SERVER["PHP_SELF"]}?download=1\">Download table</a>";

but it doesn't work beacuse headers are already set to the page. If I put the code into another page, I have the problem how to send the variable $xls to the other page?? (The variable is long and contains several \n and \t characters...)
0
Comment
Question by:winmeister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
php-webdesign earned 100 total points
ID: 12168473
you can try writing it to a txt file fput() and in the following page read it from the file fget()
0
 
LVL 1

Author Comment

by:winmeister
ID: 12168588
yes, but how can I then change to the "send" page without incurring in the: "Cannot modify header information" error?
0
 
LVL 5

Expert Comment

by:php-webdesign
ID: 12168630
in the current page you insert:

<?php
$filename = 'xls.txt';

if (is_writable($filename)) {

   if (!$handle = fopen($filename, 'w')) {
         print "Can't open file ($filename)";
         exit;
   }

   if (!fwrite($handle, $header\n$xls)) {
       print "Can't write to ($filename)";
       exit;
   }

   print "Succes, written the content to file ($filename)";

   fclose($handle);

} else {
   print "The file isn't writable... chmod 777?";
}
?>

This puts the content into the file

now create a new file

download.php

<?php
$filename = "xls.txt";
$handle = fopen ($filename, "rb");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);

          header("Content-type: application/octet-stream");
          header("Content-Disposition: attachment; filename=extraction.xls");
          header("Pragma: no-cache");
          header("Expires: 0");
          print "$contents";
          }
?>

something like this?
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 1

Author Comment

by:winmeister
ID: 12168693
Oh yes. But I don't need always to save the file. So when the user clicks on a link on page number 1, the program should:

1) save the file
2) call page #2 for downloading
3) come back to the original page

..here is where I'm getting lost.
0
 
LVL 5

Expert Comment

by:php-webdesign
ID: 12168713
well... now the page does:
1) save the file
2) starts the download

and if you add

header("Location: originalpage.php");

to the script, it redirects him to the originalpage.php, but be sure to add this line at the end of your download.php page...

or do you mean something else?
0
 
LVL 1

Author Comment

by:winmeister
ID: 12168789
no, if I add
header ("Location.....
on page #1 I am getting a "Cannot modify header information" error?

More, I have seen different behaviours between Mozilla-Firefox and IE 6.
IE6 dosen't get the filename and type, so it won't download...!
0
 
LVL 5

Expert Comment

by:php-webdesign
ID: 12168804
the Header("Location is for download.php then :)

and for IE en Firefox... sorry can't help you with them
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question