Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

javascript - Ajax Php get file from server, how to detect the file is open

There is this case. I have many files(data) in the server. I use Ajax and php for Client browser to get the data from the server.

When a person opens a website and accesses a file from the server, at the same time, if another person(user) open this website, I want to find a way to detect that file is open, if so, I can load a different file or just block this user.

How can I do this, any suggestion is appreciated, thanks for your time!

Ajax get the file

load: function (url) {
        var _this = this;
        $.ajax({
            type: "GET",
            url: url,
            dataType: "text",
            success: function (json) {
                if (typeof json == 'string' || json instanceof String) {
                    json = JSON.parse(json);
                    _this.parse(json);
                }
            }
        });
    },
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use global variables:

<?php
if($_GLOBAL["locked"]) {
     header("HTTP/1.0 503 Service Unavailable");
     exit(0);
} else {
     $_GLOBAL["locked"]=true;
     //send file
     $_GLOBAL["locked"]=false;
     exit(0);
}
?>

The variable 'locked' will persist throughout all of the php files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...