Basic sintax to export data and save in files to download

19 views
Skip to first unread message

fititnt

unread,
Jun 7, 2009, 4:48:23 PM6/7/09
to Joomla! General Development
I'm having a problem to run php code inside the joomla.

I will give a simple example.

The code below would normally save you a file that is in a directory.


//start
$file = "nome_arquivo.txt";
header("Content-Type: application/save");
header("Content-Length:".filesize($file));
header('Content-Disposition: attachment; filename="' . $file . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');

$fp = fopen("$file", "r");
fpassthru($fp);
//end


Outside of joomla, it works without problems, however, if I put inside
one administrator component, the generated file will contain ALL the
contents of one new html page in joomla instead of what it should
contain only.

This code is only an example of some more complex applications that I
would do.

In that case, what should I do to save the file it only what they
should and not the entire HTML that would be expected in a new page?

Rob Schley

unread,
Jun 10, 2009, 6:33:42 PM6/10/09
to joomla-de...@googlegroups.com
After you output the file, close the application.

// Close the application.
$app = &JFactory::getApplication();
$app->close();

Best,
Rob

fititnt

unread,
Jun 10, 2009, 8:47:50 PM6/10/09
to Joomla! General Development
Thanks Rob!

Was just it.

On 10 June, 19:33, Rob Schley <rob.sch...@joomla.org> wrote:
> After you output the file, close the application.
> // Close the application.
> $app = &JFactory::getApplication();
> $app->close();
>
> Best,
> Rob
>
Reply all
Reply to author
Forward
0 new messages