简体   繁体   中英

How to check PHP if statement without reloading page

I am trying to check a PHP if statement without reloading the page. I have a download page made with PHP ----.co m/download.php The page has a "Download" button, which downloads ----.co m/file.zip The download page counts how many times the file has been downloaded and records it to a MySQL database. After a certain number of downloads on the file, I want the PHP to use copy() and replace the file with a new file. However, I don't want the user to have to visit ----.co m/download.php for the PHP to run the following:

else if ($fileInfos->downloads > 35) {
copy($newfile, file.zip) }

If the user visits the direct download link, the database updates the download number. How can I make the PHP run the above code without a user having to visit the download.php page?

You can't. What you can do, if your server allows, is run a cron-job that checks intermittently if the file should be replaced. Of course you should also run the check ON the download page (so if the user selects to download a file, it will be checked if it should be replaced before it gets sent to the user).

Depending on how many times this needs to happen, a cron-job might be a bit too much, though, but again, if you can get away with checking every minute, or 5 minutes, that will work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM