$filename 传递文件名,返回最新路径的文件名,前端经过打包处理的直接忽略。 function newf($filename) { $filestr = file_get_contents(public_path('file_version.json')); if (empty($filestr)) { $filearr = array(); $f
function newf($filename) { $filestr = file_get_contents(public_path('file_version.json')); if (empty($filestr)) { $filearr = array(); $filearr[$filename]['key'] = md5_file(public_path($filename)); $filearr[$filename]['src'] = $filename . "?" . time(); } else { $filearr = unserialize($filestr); if (in_array($filename, array_keys($filearr))) { if ($filearr[$filename]['key'] != md5_file(public_path($filename))) { $filearr[$filename]['key'] = md5_file(public_path($filename)); $filearr[$filename]['src'] = $filename . "?" . time(); } } else { $filearr[$filename]['key'] = md5_file(public_path($filename)); $filearr[$filename]['src'] = $filename . "?" . time(); } } file_put_contents(public_path('file_version.json'), serialize($filearr)); return $filearr[$filename]['src']; }