Boa tarde galera... tenho hoje um script que faz upload de um unico arquivo, cria um tumb, coloca uma marca e transforma em png... porem agora gostaria de fazer com que ele fizesse uploads de varios arquivos de uma so vez... gostaria de uma ajuda, tentei com for, mas não consigo de jeito nenhum. Segue meu codigo: <?php
$overlay = 'mascara.png';
$trans_r = 255;
$trans_g = 255;
$trans_b = 255;
$cache_fs = 'cache/';
$cache_uri = 'http://localhost/upload_foto/cache/';
$srid = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['REMOTE_PORT'] . time());
$base_fs = $cache_fs . $srid;
$base_uri = $cache_uri . $srid;
if(!$overlay = imagecreatefrompng($overlay)) {
$error = 'Erro ao abrir a máscara';
$show = 'error';
}
else if(isset($_FILES[foto])) {
switch($_FILES[foto][type]) {
case 'image/jpeg':
case 'image/pjpeg':
$orig = imagecreatefromjpeg($_FILES[foto][tmp_name]);
break;
case 'image/png':
$orig = imagecreatefrompng($_FILES[foto][tmp_name]);
break;
case 'image/gif':
$orig = imagecreatefromgif($_FILES[foto][tmp_name]);
break;
default:
$error = 'Formato de arquivo inválido';
$show = 'error';
}
if($orig) {
$orig_x = imagesx($orig);
$orig_y = imagesy($orig);
$overlay_x = imagesx($overlay);
$overlay_y = imagesy($overlay);
$image_x = 800;//Largura da imagem grande
$thumb_x = 150;//Largura da imagem pequena
$image_y = round(($orig_y * $image_x) / $orig_x);
$thumb_y = round(($orig_y * $thumb_x) / $orig_x);
//Posição da Máscara - Alinhado abaixo a esquerda
$offset_x = 0;
$offset_y = $image_y - $overlay_y;
$image = imagecreatetruecolor($image_x, $image_y);
imagecopyresampled($image, $orig, 0, 0, 0, 0, $image_x, $image_y, $orig_x, $orig_y);
imagecolortransparent($overlay, imagecolorallocate($overlay, $trans_r, $trans_g, $trans_b));
imagecopymerge($image, $overlay, $offset_x, $offset_y, 0, 0, $overlay_x, $overlay_y, 99);
$thumb = imagecreatetruecolor($thumb_x, $thumb_y);
imagecopyresampled($thumb, $orig, 0, 0, 0, 0, $thumb_x, $thumb_y, $orig_x, $orig_y);
imagepng($image, $base_fs . '-grande.png');
imagepng($thumb, $base_fs . '-pequena.png');
$image_uri = $base_uri . '-grande.png';
$thumb_uri = $base_uri . '-pequena.png';
}
else {
if(!$error)
$error = 'Erro ao enviar a imagem';
$show = 'error';
}
if(!isset($show))
$show = 'result';
}
if($show == 'error') {
echo "<h2>$error</h2>";
} else if($show == 'result') {
echo "<h2>Imagem Redimensionada</h2>";
echo "<p><img src=\"$image_uri\"></p>";
echo "<h2>Imagem Pequena</h2>";
echo "<p><img src=\"$thumb_uri\"></p>";
} else {
?>
<script>
function addRow() {
document.sendmessage.countx.value = parseInt(document.sendmessage.countx.value) + 1;
var i = parseInt(document.sendmessage.countx.value);
var table;
if (document.all)
table = document.all.uploadtable;
else if (document.getElementById)
table = document.getElementById('uploadtable');
if (table && table.rows && table.insertRow) {
var tr = table.insertRow(table.rows.length);
var td = tr.insertCell(tr.cells.length);
data = '<input type="file" name="foto" class="textboxgray" style="Font-Family:Arial; Font-Size:11px; Color:#AA0000;"><br>';
td.innerHTML = data;
}
}
</Script>
<form name="sendmessage" enctype="multipart/form-data" method="post" action="index.php">
<B><Font Color="#AA0000">Mais arquivos?:</Font></B> <input type="button" name="add" value=" + " class="textboxgray" onClick="java script: addRow()" style="Font-Family:Arial; Font-Size:11px; Color:#000000;">
<Hr>
<input type="hidden" name="countx" value="1">
<table border="0" cellspacing="1" cellpadding="2" id="uploadtable">
<tr>
<td>
<input type="file" name="foto" class="textboxgray" style="Font-Family:Arial; Font-Size:11px; Color:#AA0000;">
</td>
</tr>
</table>
<input type="submit" name="Submit" value="Upload" class="textboxgray" style="Font-Family:Arial; Font-Size:11px; Color:#000000;">
</form>
<?}?>