【问题标题】:How to create event&listener to check if there is specific file in folder如何创建事件侦听器以检查文件夹中是否有特定文件
【发布时间】:2017-05-26 08:38:13
【问题描述】:

我想听例如存储目录是创建的特定文件以及是否要执行某些操作。如何创建监听和事件类来做到这一点?

【问题讨论】:

  • this你需要什么?
  • @hungrykoala,我需要侦听器来检查此函数是否已创建文件,但作为侦听器会通知我文件已创建。

标签: php laravel events listener


【解决方案1】:
window.setInterval(function() {

$.ajax({
    url: 'http://www.example.com/somefile.ext',
    type: 'HEAD',
    error: function() {
        //file not exists
    },
    success: function() {
        //file exists
    }
});

        }, 5000); // you can change this time interval as you want

检查 404 状态的代码,

    function UrlExists(url) {
        var http = new XMLHttpRequest();
        http.open('HEAD', url, false);
        http.send();
        return http.status != 404;
    }

【讨论】:

    【解决方案2】:

    该文件是-肯定-在 PHP 端创建的。
    所以有一个特定的代码块可以做到这一点。

    所以你知道从哪里开始。

    现在创建文件的时间取决于您希望“确认”存储或显示的位置、时间和方式...有许多选项

    我建议你阅读PHP file_put_content
    在您拥有的代码中找到它并尝试一下。

    【讨论】:

      猜你喜欢
      • 2010-09-23
      • 2018-10-11
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多