Codice PHP:
<?php
$dir = 'images/composer/';
if(!is_dir($dir)) mkdir($dir);
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
unlink($dir . $file);
}
}
closedir($handle);
}
$immagini = array();
foreach($_FILES['files'] as $k => $v)
{
foreach($v as $x => $vx)
{
$immagini[$k][] = $vx;
}
}
$width = count($immagini['name']) * 80;
$height = 80;
header( "Content-Type: image/png" );
$im = @imagecreatetruecolor($width, $height)
or die('Errore inizializazione dello stream GD immagine');
#$text_color = imagecolorallocate($im, 255, 255, 255);
#imagestring($im, 1, 5, 5, 'Sneh!', $text_color);
$x = 0;
for($i = 0; $i < count($immagini['name']); $i++)
{
$corrente = imagecreatefrompng($immagini['tmp_name'][$i]);
list($widthx, $heightx) = getimagesize($immagini['tmp_name'][$i]);
/*imagepng($corrente,$dir.uniqid()."corrente.png");
$correntex = imagecreatefrompng($dir.uniqid()."corrente" . $i . ".png");*/
$thumb = imagecreatetruecolor(80, 80);
imagecopyresized($thumb, $corrente, 0, 0, 0, 0, 80, 80, $widthx, $heightx);
imagecopymerge($im , $thumb, $x, 0, 0, 0, 80, 80, 100);
$x+=80;
}
$nome_img = $dir . uniqid() . ".png";
imagepng($im, $nome_img);
imagedestroy($im);
?>
<pre>
<?php
print_r($immagini); #Questo è l'offset, ma basta anche printare i $_files['files']
?>
</pre>