-2

as the title suggests, I need to view images and then erase them from the disk. I can export them from the db and have them displayed correctly, but then I stop: either I visualize them or I delete them. I can't do both.

at the end of page, Afer the php code i try this:

<script type="text/javascript">
document.addEventListener('readystatechange', event => {

if (event.target.readyState === "interactive") {   
    setTimeout(function(){
        <?php
        $tags = explode('|',$del);
        foreach($tags as $key) {    
            exec ('rm -f '.$path.$key.'.gif');    
        }
        ?>

    }, 7000);
}

});
</script>

in this javascript if i insert a message it displays it (e.g. hello world) after the full load of the page and after the interval. If I enter the php code it executes it immediately. Why?

Xar
  • 1
  • 1
  • 1
    I don't get your question. Where does it select anything from a database? And please look up the difference between server-side programming (in PHP) and client-side (in JS) – Nico Haase Mar 05 '20 at 10:57
  • https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – RiggsFolly Mar 05 '20 at 10:58
  • In regards to *If I enter the php code it executes it immediately* ... is the nature of PHP rendering. It will execute before the DOM is fully loaded. So the difference would be a js event which does dynamic type things, for the PHP to also be dynamic, you'd need an AJAX call in your event handler to another (or same) PHP script. – GetSet Mar 05 '20 at 11:01

1 Answers1

0

I don't know anything about ajax :\ so, how could I modify the script to make those few instructions in php execute after the page has been completely loaded?

Xar
  • 1
  • 1