Created
November 9, 2017 22:43
-
-
Save mxmaxime/34e74d096b10251af8396c2d12e3ebd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function assets($path) | |
{ | |
$file = realpath($path); | |
if (!file_exists($file)) throw new Exception("Le fichier {$file} n'existe pas"); | |
$mtime = filemtime($file); | |
$path_info = pathinfo($path); | |
$newPath = $path_info['dirname'] . '/' . $path_info['filename'] . '.' . hash('md5', $mtime) . '.' . $path_info['extension']; | |
$newRealPath = realpath($newPath); | |
if (!file_exists($newRealPath)) { | |
copy($file, $newRealPath); | |
} | |
return $newPath; | |
} | |
?> | |
// Utilization | |
<img src="<?= assets("img/coffee.jpg") ?>" alt="coffeeeeeeeeeeee"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment