Images dynamic naming
In order to improve seo, it is possible to name the images and the path to the images dynamically
We call the method getDynImage of any method of the collector, passing gen parameter of the table of the object in, then the field name of the image that you want to display, and then an array containing the labels that you want to use
For example :
$this->collector['treeview']->getDynImage($treeview,'file',array('wording-of-product'))
Will display :
/dimg2/treeview/file/812/libelle-du-produit.jpg
Another example :
$this->collector['treeview']->getDynImage($treeview,'file',array('cat1','cat2','my-product'))
Will display :
/dimg2/treeview/file/812/cat1/cat2/mon-produit.jpg
$this->collector['treeview']->getDynImage($treeview,'file',array($title))
Will display :
/dimg2/treeview/file/812/aromessence.jpg
Put in the vhost apache :
RewriteRule ^/dimg2/([^/]*)/([^/]*)/([^/]*)/(.*)$ /dimg2.php?mod=$1&field=$2&id=$3&p=$4 [P]
Contents of the file controller, in our example dimg2.php:
ob_get_clean();
$mod = (isset($_GET['mod'])) ? $_GET['mod'] : 'products' ;
$field = (isset($_GET['field'])) ? $_GET['field'] : 'media' ;
$id = (isset($_GET['id'])) ? $_GET['id'] : ";
$mod = filter_var($mod,FILTER_SANITIZE_STRING);
$field = filter_var($field,FILTER_SANITIZE_STRING);
$id = filter_var($id,FILTER_SANITIZE_NUMBER_INT);
$file = $_SERVER['DOCUMENT_ROOT'].urldecode($element[$field]);
$content = file_get_contents($file);
header('Content-Type: '.image_type_to_mime_type(exif_imagetype($file)));
readfile($file);
die();