Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send long string as aparameter

Posted on 2004-09-28
7
Medium Priority
?
320 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 300 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

722 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