douhuigang9550 2018-08-11 14:56
浏览 57

PHP:如何动态更改文件中的输出

Redirect output do minified.js file

file_put_contents("minified.js", $packer->pack());

This redirects the output to the minified.js file. If I change anything in the code, the output is not updated in minified.js. I must always delete the content and run it again.

How can I do this dynamically and make the content in minified.js always replaced automatically?

  • 写回答

2条回答 默认 最新

  • dongyan1899 2018-08-11 15:38
    关注

    Check the last modification time of the file where the original version is located.

    $original_file = $_SERVER["DOCUMENT_ROOT"].'/main.js';
    
    $last_modified = date("Y-m-d H:i:s", filemtime($original_file));
    
    file_put_contents($last_modified, $_SERVER["DOCUMENT_ROOT"].'/date.txt');
    $last_modified_read = file_get_contents($_SERVER["DOCUMENT_ROOT"].'/date.txt');
    
    if(strtotime($last_modified_read) < strtotime($last_modified)){
      echo "Minify!";
      file_put_contents($_SERVER["DOCUMENT_ROOT"].'/date.txt', $last_modified);
    }
    

    filemtime()

    评论

报告相同问题?

悬赏问题

  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题