<?php
/**
 * Library module
 *
 * save image to disk
 *
 * @package linea21\core\library
 * @author $Author$ - Simon Georget <simon@linea21.com>
 * @version $Id$
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

session_start();
include_once('../config/define.php');

//////////// Check Droits utilisateur ////////////
if (!$l21auth->isAuthenticated() || $l21auth->isSimpleUser()) ReloadIndex('admin');
////////////

$tmp_path = '../tmp/report/';

$images = $_POST['images'];
$names = $_POST['names'];

// print_r($_REQUEST);

if(count($images) === 0) return;

// On créer le dossier si nécessaire
if(!file_exists($tmp_path)) mkdir($tmp_path, '0755');

for($i = 0; $i < count($images); $i++) {
	// echo $i.'<br>';
	
	$image = str_replace('data:image/png;base64,', '', $images[$i]);
	$decoded = base64_decode($image);
	
	// file is automatically overwritten
	file_put_contents($tmp_path . $names[$i] .'.png', $decoded, LOCK_EX);

}

?>