The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Create CSV or PDF files with php - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: Create CSV or PDF files with php (/showthread.php?tid=1072)



Create CSV or PDF files with php - pittsburgh1776 - 06-01-2018

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>
Code:
<?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


Create CSV or PDF files with php - Brandin - 06-01-2018

Just call init.php and use securePage still.


Create CSV or PDF files with php - pittsburgh1776 - 06-02-2018

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:

Code:
$db = DB::getInstance();

I just forgot it.

Thorsten


Create CSV or PDF files with php - mudmin - 06-02-2018

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/