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:

  1. by setting environment variable
  2. creating configuration file cli job.
  3. setting document_root index directly in php (eg: $_server['document_root'] = '/path/to/document/root';)
    1. 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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -