Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 707

I search a better solution, more native [closed]

$
0
0

Hello i have make a solution for track progress event while execution to my binary software with a exec. So i launch exec with php and send sdtout in a file txt.

$commande = $myClass::prepare_commande();$size = filesize(str_replace('\\', '/', getcwd().'/optimages.exe'));exec($commande.'> '.$_SESSION['dir'].'/progress.txt', $output, $out);$sortie = $output;

I send ajax like that:

req.start = function(url, data, texte) {    req.progress();    return new Promise((resolve, reject) => {        $.ajax({            type: 'POST',            url: url,            data: data,            cache: false,            beforeSend: function() {                Swal.fire({heightAuto:false,title: "<p>"+texte+"</p>",theme:'dark',html: "<p class='titre-progress'>0%</p><div id='bar-progress'></div>"});                req.inter = setInterval(req.progress, 200);            },            complete: function(retour) {                $('.titre-progress').text('100%');$(drag.bar_progress).css('width', '100%');                swal.close();                clearInterval(req.inter);                resolve(retour);            },            dataType: 'json'        });    });};req.progress = function(){    if($(".swiper-slide-active img").length > 0) {        var str = $(".swiper-slide-active img").attr('src').split('/');        var dir_path = 'temp/'+str[str.length - 2]+'/';        $.ajax({             method: "POST",            url: "./assets/php/progression.php",             cache: false, dataType:'json',            data: {'getprogress': dir_path},            complete: function(retour) {                //console.log(retour);                var progression = parseInt(retour.responseJSON);                if(!isNaN(progression)){                    $('.titre-progress').text(String(progression)+'%');                    $(drag.bar_progress).css('width', String(progression) +'%');                }            }        });    }};

The code for read progress task with a request injax intermediate

$sortie = "";if(isset($_POST['getprogress'])){        if(file_exists($_POST['getprogress'].'progress.txt')){            $tab = file($_POST['getprogress'].'progress.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);            $size = sizeof($tab);            if($size > 0){                $sortie = $tab[$size-1];            }        }}echo json_encode($sortie);

I search a better solution, more native, If anyone knows a more elegant solution I would be happy to see it.


Viewing all articles
Browse latest Browse all 707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>