Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Questions related to using nuBuilder Forte.
kev1n
nuBuilder Team
Posts: 4307 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:
Unread post
by kev1n » Thu Oct 15, 2020 8:31 am
Tested with xampp and it works fine - but only after the temp directory has been created manually.
I think nuSavePDF() can be modified to create the temp dir if it doesn't exist.
@Steven/Janusz: Would that work for you?
Code: Select all
function nuSavePDF($PDF){
// output to file
$filename1 ='nupdf_'.nuID().'.pdf';
$dir = getcwd().'/temp/'; // for linux
if (!is_dir($dir)) {
mkdir($dir, 0777);
}
$filename = $dir.$filename1;
$PDF->Output($filename,'F');
$s = nuHash();
$usr = $s["USER_ID"];
$rid = nuID();
// after created initially you can comment/exclude creation of the pdf_temp table
$q1 = "
CREATE TABLE IF NOT EXISTS pdf_temp (
pdf_temp_id VARCHAR(25) PRIMARY KEY,
pdf_added_by VARCHAR(25),
pdf_file_name VARCHAR(255),
pdf_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); ";
nuRunQuery($q1);
$q1 = "INSERT INTO pdf_temp (pdf_temp_id,pdf_added_by,pdf_file_name)
VALUES ('$rid','$usr','$filename');";
nuRunQuery($q1);
}
PS: I guess nupdf_5f87508687b938f.pdf can be removed.
https://github.com/steven-copley/nubuil ... 1d3a7bbae8
Janusz
nuBuilder Team
Posts: 506 Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times
Unread post
by Janusz » Thu Oct 15, 2020 9:03 am
Just for info:
regarding Windows system where I observed the need of backslashes it's on:
>>>var_dump(PHP_OS);
string(5) "WINNT"
and the exact code context is:
Code: Select all
.....
// define file name
$filename1 = 'file'.nuID().'.csv';
$filename = getcwd().'\temp\\'.$filename1;
// file creation
$file = fopen($filename,"w");
$x1=iconv( "UTF-8","WINDOWS-1250", $x1);
fwrite($file,$x1);
fclose($file);
// download
header("Content-Description: File Transfer");
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=".$filename1);
readfile($filename);
// deleting file
unlink ($filename);
....
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506 Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times
Unread post
by Janusz » Thu Oct 15, 2020 9:41 am
On Debian after creation there is chmod needed additonally to have writing:
(the mkdir with 0777 is making just 755)
Code: Select all
$dir = getcwd().'/temp/'; // for linux
if (!is_dir($dir)) {
mkdir($dir);
chmod($dir, 0777);
}
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506 Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times
Unread post
by Janusz » Thu Oct 15, 2020 9:58 am
and additional info:
when I run above code from the root terminal outside nuBuilder as php code it works.
when I placed it into nuBuilder nurunpdf.php file the directory is not created
PHP Warning: mkdir(): Permission denied in /var/www/html/TxDB-New/nurunpdf.php on line 1165,
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506 Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times
Unread post
by Janusz » Thu Oct 15, 2020 10:43 pm
potentially the function can be extended with error message in nuDebug in case file can not be saved in temp folder:
Code: Select all
function nuSavePDF($PDF){
// output to file
$filename1 ='nupdf_'.nuID().'.pdf';
$filename = getcwd().'/temp/'.$filename1; // for linux
if (touch($filename) == TRUE) {
$PDF->Output($filename,'F');
$s = nuHash();
$usr = $s["USER_ID"];
$rid = nuID();
// after created initially you can comment/exclude creation of the pdf_temp table
$q1 = "
CREATE TABLE IF NOT EXISTS pdf_temp (
pdf_temp_id VARCHAR(25) PRIMARY KEY,
pdf_added_by VARCHAR(25),
pdf_file_name VARCHAR(255),
pdf_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); ";
nuRunQuery($q1);
$q1 = "INSERT INTO pdf_temp (pdf_temp_id,pdf_added_by,pdf_file_name)
VALUES ('$rid','$usr','$filename');";
nuRunQuery($q1); }
else {
nuDebug('nuRunReportSave() Error; PDF file not created. Check if ./temp folder exists with writting permission.');
}
}
to be verified if it's ok as well on windows
If you like nuBuilder, please leave a review on SourceForge
admin
Site Admin
Posts: 2815 Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times
Unread post
by admin » Fri Oct 16, 2020 2:41 am
Guys,
The reason I left a file in the temp directory is so that cloning the nuBuilder directory with Github would force the creation of the temp directory.
Are you updating nuBuilder in a different way?in a different way?
Steven
kev1n
nuBuilder Team
Posts: 4307 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:
Unread post
by kev1n » Fri Oct 16, 2020 4:30 am
Steven, you're making a valid point. The majority of people wouldn't face this issue since the temp directory already exists.
I for one (and I believe Janusz too) update in an unconventional way since I'm maintaining a nuBuilder version with custom patches (eg. WP stuff excluded etc)
Just leave the function as it is - there's no need to create the temp directory in code.
Janusz
nuBuilder Team
Posts: 506 Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times
Unread post
by Janusz » Fri Oct 16, 2020 6:09 am
Steven,
From my point of view - current status with the temp directory is completely fine and should be left as it is now (with a file inside due to github requirement)
It would be nice to add somewhere the remark that ./temp directory should have writing rights (for example remark in Wiki or with message in nuDebug).
Janusz
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4307 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:
Unread post
by kev1n » Fri Oct 16, 2020 6:40 am
Janusz wrote: Steven,
or with message in nuDebug).
A try ... catch should do the job to catch all possible exceptions that may occur.
Code: Select all
try{
$PDF->Output($filename,'F');
} catch(Exception $ex){
nuDisplayError('Error while saving the PDF file: . $ex->getMessage());
return false;
}