php - TCPDF ERROR on pdf generator launched by cron -
i have problem pdf generator script (using html2pdf lib). the script works when launched manually returns error when launched cron task.
tcpdf error: unable create output file: /0000/images/upload/demonstration/factures/2016-05-demonstration.pdf
here's part of script involved in creation.
require('html2pdf/html2pdf.class.php'); try { $pdf = new html2pdf('p','a4','fr'); $pdf->writehtml($content); ob_end_clean(); $pdf->output(''.$_server['document_root'] . '/0000/images/upload/'.$data["id_client"].'/factures/'.$fichier.'.pdf', 'f'); } catch(html2pdf_exception $e) { die($e); }
i tried many solutions suggested in other threads nothing worked far. files , directories have permissions 777 , i'm using right absolute path (the fact works manually proves it).
any idea ?
$_server['document_root'] not available when running php via command line since document_root apache variable set in vhost config. can see in error message variable empty , it's trying write directory called "0000" in root of operating system.
you have set document root other way when running via cli like:
- by setting environment variable
- creating configuration file cli job.
- setting document_root index directly in php (eg: $_server['document_root'] = '/path/to/document/root';)
- hard coding path
step 1
figure out document root is. can way:
die(var_dump($_server['document_root']));
make sure run above temp code via web browser (not cron) , tell document root is.
step 2
pick 1 of options provided above.
let's choose option 4 (hard coding). replace $_server['document_root'] in code whatever path got in step 1 above. work both via browser , via cron.
important note: document root changes between servers if going next deploy code server have know document root on specific server.
Comments
Post a Comment