Ajax Php从服务器获取文件,如何检测文件是否打开 [英] Ajax Php get file from server, how to detect the file is open

查看:68
本文介绍了Ajax Php从服务器获取文件,如何检测文件是否打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这种情况. 我的服务器中有很多文件(数据).我使用Ajaxphp表示Client browser从服务器获取数据.

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获取文件

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);
                }
            }
        });
    },

推荐答案

您可以使用全局变量:

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

变量"locked"将在所有php文件中持续存在.

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

这篇关于Ajax Php从服务器获取文件,如何检测文件是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆