Bonjour,
J'ai un soucis avec un script php. Le fichier généré est un fichier txt dans lequel il devrait y avoir des retours à la ligne... Sauf que lorsque j'édite mon fichier avec mon bloc note de mon serveur cela ne fonctionne pas. Si j'édite avec mon bloc note sur mon poste Windows 11 cela fonctionne... Ce fichier est importé dans un logiciel et il ne fonctionne pas, il n'interprète donc pas non plus le retour à la ligne... je sèche. J'ai essayé en mettant \n puis \r\n puis PHP_EOL mais rien n'y fait...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
 
//cas de la tâche planifiée
if (!empty($argv[1]) && $argv[1] === 'planif') {
    $url = 'passerelle_carburant';
    require_once dirname(__FILE__) . '/../../config.php';
    require_once dirname(__FILE__) . '/../../model/common/Utils.php';
    \Common\Utils::initAutoloader();
    try {
        $nameFile = date('Ymd_His') . '_export.txt';
        $pathLog = dirname(__FILE__) . '/../../log/' . $nameFile;
        if (file_exists($pathLog)) {
            unlink($pathLog);
        }
        $fileLog = fopen($pathLog, 'c+b');
        $cpyMan = new \Admin\Company\CompanyManager(new Common\DAO(DB_CONFIG));
        $tabCpy = $cpyMan->getAll();
        $expMan = new Report\ExportManager(new Common\DAO(DB_EPACK));
		foreach ($tabCpy as $cpy) {
            $dataRes = $expMan->getAll(['month' => date('m') - 1, 'year' => date('Y'), 'cpy' => $cpy]);
            fwrite($fileLog, 'Société : ' . $cpy->getName() . "\r\n");
            fwrite($fileLog, '- Consommation : ' . $dataRes['conso'] . "\r\n");
            fwrite($fileLog, '- Refacturation : ' . $dataRes['refact'] . "\r\n");
        }
        fclose($fileLog);
        $mail = new Common\Mail('Passerelle carburant - Export automatique', 'L\'export mensuel s\'est déroulé avec succès', DEST_MAIL, ['si@gmail.com' => 'Service informatique']);
        $mail->addFile(['name' => $nameFile, 'tmp_name' => $pathLog, 'type' => 'application/txt', 'size' => filesize($pathLog)]);
        $mail->sendMail();
    } catch (\Admin\AdminException | Exception | Swift_SwiftException $exc) {
        fwrite($fileLog, 'Erreur lors de l\'export mensuel ' . $exc->getMessage());
        $mail = new Common\Mail('Passerelle carburant - Erreur', 'Une erreur est survenue lors de l\'export mensuel : ' . $exc->getMessage(), DEST_MAIL, ['si@gmail.com' => 'Service informatique']);
        $mail->sendMail();
    }
} else {
    require_once(dirname(__FILE__) . '/../../view/template/header.php');
    if (empty($_SESSION['authentPasserelleCarburant']['authent']) && empty(filter_input(INPUT_GET, 'planif'))) {
        require(dirname(__FILE__) . '/../../view/template/noaccess.php');
    } else {
        try {
            $safePost = filter_input_array(INPUT_POST);
            $yearSel = empty($safePost['year']) ? date('Y') : $safePost['year'];
            $monthSel = empty($safePost['month']) ? date('m') - 1 : $safePost['month'];
            if (!empty($safePost)) {
                $cpy = unserialize(urldecode($safePost['cpy']));
                $expMan = new Report\ExportManager(new Common\DAO(DB_EPACK));
                $dataRes = $expMan->getAll(['month' => $monthSel, 'year' => $yearSel, 'cpy' => $cpy]);
            }
        } catch (Admin\AdminException $ex) {
            echo new \Common\Alert($ex->getMessage(), 'error');
        }
    }
    include (dirname(__FILE__) . '/../../view/export/v_export.php');
    include (dirname(__FILE__) . '/../../view/template/footer.php');
}