Best way to determine if a file is empty (php)?

前端 未结 5 1445
迷失自我
迷失自我 2020-12-01 15:40

I\'m including a custom.css file in my template to allow site owners to add their own css rules. However, when I ship the file, its empty and there\'s no sense loading it if

5条回答
  •  盖世英雄少女心
    2020-12-01 16:07

    filesize() would be more efficient, however, it could be misleading. If someone were to just have comments in there or even just whitespace...it would make the filesize larger. IMO you should instead look for something specific in the file, like /* enabled=true */ on the first line and then use fopen/fread to just read the first line. If it's not there, don't load it.

提交回复
热议问题