X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fmain.inc;fp=includes%2Fmain.inc;h=018fb2b0cdc9b0869d2418969b231d838518563c;hb=a3d4d43e85917835a61b9b85b3e56c53e9d0e342;hp=8ef038ca1f06e63e39959c250889781cebee05f1;hpb=12cf04cc979ec556acc4ee8106ee1c89e0b35bb7;p=fa-stable.git diff --git a/includes/main.inc b/includes/main.inc index 8ef038ca..018fb2b0 100644 --- a/includes/main.inc +++ b/includes/main.inc @@ -69,13 +69,34 @@ function cache_js_file($fpath, $text) if(!$go_debug) $text = js_compress($text); - $file = fopen($fpath, 'w'); + $file = force_open($fpath); if (!$file) return false; if (!fwrite($file, $text)) return false; return fclose($file); } +/* + Open file for writing with creration of subfolders if needed. +*/ +function force_open($fname) +{ + $file = pathinfo($fname); + + $path = $fname[0] == '/' ? '/' : ''; + $tree = explode('/', $file['dirname']); + foreach($tree as $level) { + $path .= $level; + if (!file_exists($path)) { + if (!mkdir($path)) { + return null; + } + } + $path .= '/'; + } + return fopen($fname, 'w'); +} + function add_js_file($filename) { global $js_static;