2017-10-06 10 views
1

J'utilise Phantomjs et ça ne marche pas bien. Je suis la génération d'un PDF à partir de ma page web avec cette commande:phantomsjs fonctionne sur commande mais pas avec exec() PHP

/var/www/html/hor/js/phantomjs /var/www/html/hor/js/_generate.js 1234 

Il fonctionne bien (il ne trouve pas le fichier de kit d'interface utilisateur, je ne l'ai pas encore examiné la question) et j'ai mon PDF dans mon PDF annuaire. Mais avec mon fichier PHP, je n'ai rien.

commande ou PHP à la fois le code d'erreur suivant avec print_r():

TypeError: 'undefined' is not a valid argument for 'in' (evaluating 
'"default"in t') 

http://localhost/js/uikit.min.js:3 
http://localhost/js/uikit.min.js:3 
http://localhost/js/uikit.min.js:3 

(Donc, dans les deux cas, le script a été lancé)

Mon script PHP:

<?php 
    $token = $_GET['token']; 
    $simul_mail = $_GET['simulmail']; 

    $cmd = ' /var/www/html/hor/js/phantomjs'; 
    $cmd.= ' /var/www/html/hor/js/_generate.js'; 
    $cmd.= ' '.$token; 

    if(isset($_GET['simulmail'])&&isset($_GET['token'])){ 
     exec($cmd, $output); 
    } 
    print_r($output); 
?> 

Mon fichier _generate.js exécuté par phantomJS:

fs = require('fs'); 
system = require('system'); 
token = system.args[1]; 

if(token!=null && token!=""){ 

    fs.changeWorkingDirectory('/var/www/html/hor/pdf/'); 

    var page = new WebPage(); 
    var pagename = "PDF_"+token+".pdf"; 

    page.open('http://localhost/_template-mail.php?v='+token, function (status) { 
     page.render(pagename); 
     phantom.exit(); 
    }); 

} 
else{ 
    phantom.exit(); 
} 

Que puis-je faire?

Répondre

1

Pour ceux avec le même problème, il s'agissait d'une question sur les droits.

Apache n'avait pas le droit d'écrire dans mon dossier PDF.
PhantomJS avec exec() utilise les droits de PHP qui utilise les droits d'Apache.

Si Apache est le propriétaire du dossier, cela fonctionne très bien!

--> sudo chown <your username>:<your usergroup> -R <path to>/folder 
sudo chown apache -R /var/www/html/hor/pdf