This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

Create CSV or PDF files with php

In UserSpice 4.3 and Below · Started by pittsburgh1776 on 2018-06-01 8:41 am · 11569 views · 3 replies

Hi,
I am working for three months with userspice and it is great php framework.

I have now one problem: I would like to create an csv (or an pdf) file.

I set up an php file and gave this file access with the page management function.

I have this code in the current userspice 4.3 version:

<pre>
<?php
require_once '../users/init.php';
require_once $abs_us_root.$us_url_root.'users/includes/header.php';
require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';

if (!securePage($_SERVER['PHP_SELF'])){die();}

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// .. here the content
</pre>


This created an csv file almost like I wanted. The only thing is, that I do have the html code of the header and the navigation in my csv file.

I thought I just had to delete the three 'requiered_once' lines. But then the system does not found my php file anymore.

How can I create a file without the header and navigaton code, but with access control?

Best regards

Thorsten
Just call init.php and use securePage still.
Thank you. Now it works.

I did another mistake: If you skip the header file, but you still want to access the database, you have to add this code:
$db = DB::getInstance();

I just forgot it.

Thorsten
You can do some really cool reports with this...
http://www.fpdf.org/

Takes a tiny bit of getting used to but it produces some really nice results.
http://www.fpdf.org/