Codice PHP:
<?php
error_reporting(E_ALL);
?>
<?
//percorsi cartelle per il caricamento dei files
$cartella_thumbs = "../../public/foto/montagne/";
$cartella_upload = "../../public/foto/varie/";
//la larghezza delle miniature, in pixel
$img_thumb_width = 600;
//visualizza il modulo di caricamento file
{
?>
<?
}
else
{
//verifica le dimensioni del file caricato
if($_FILES['data']['size'] ==0)
{
die('Errore : campo upload nullo');
}
// Ottengo le informazioni sull'immagine
list($width, $height, $type, $attr) = getimagesize($_FILES['image']['tmp_name']);
// Controllo che le dimensioni (in pixel) non superino 600x800
if (($width > 600) || ($height > 800))
{
die(' Dimensioni non corrette');
}
$file_permessi = array("image/pjpeg","image/jpeg");
if(!in_array($_FILES['data']['type'], $file_permessi))
{
die('Estensione non consentita');
}
///////////////////////
//crea la thumbsnail///
//////////////////////
$ThumbWidth = $img_thumb_width;
//crea la nuova immagine
if($_FILES['data']['size']){
if($_FILES['data']['type'] == "image/pjpeg" || $_FILES['data']['type'] == "image/jpeg"){
$new_img = imagecreatefromjpeg($_FILES['data']['tmp_name']);
}elseif($_FILES['data']['type'] == "image/x-png" || $_FILES['data']['type'] == "image/png"){
$new_img = imagecreatefrompng($_FILES['data']['tmp_name']);
}elseif($_FILES['data']['type'] == "image/gif"){
$new_img = imagecreatefromgif($_FILES['data']['tmp_name']);
}
//ottiene larghezza e altezza dell'immagine originale.
list($width, $height) = getimagesize($_FILES['data']['tmp_name']);
//calcola le proporzioni e ottiene dimensioni thumbsnail
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}
//funzione per ridimensionare l'immagine.
if (function_exists(imagecreatetruecolor)){
$resized_img = imagecreatetruecolor($newwidth,$newheight);
}else{
die("Errore: Assicurati che sul tuo server siano installate le GD library");
}
//ridimensionamento
if($_FILES['data']['type'] == "image/x-png" || $_FILES['data']['type'] == "image/png"){
imagealphablending($resized_img, false);
}
imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//salva l'immagine
$nome_file = strtolower($_FILES['data']['name']);
if($_FILES['data']['type'] == "image/pjpeg" || $_FILES['data']['type'] == "image/jpeg"){
imagejpeg ($resized_img,"$cartella_thumbs/$nome_file");
}
elseif($_FILES['data']['type'] == "image/x-png" || $_FILES['data']['type'] == "image/png"){
imagesavealpha($resized_img, true);
imagepng ($resized_img,"$cartella_thumbs/$nome_file");
}
elseif($_FILES['data']['type'] == "image/gif"){
imagegif($resized_img,"$cartella_thumbs/$nome_file");
}
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
}
if(!is_uploaded_file($_FILES['data']['tmp_name']))
{die('Erroe nel caricamento');
}
move_uploaded_file($_FILES['data']['tmp_name'],$cartella_upload .$nome_file)
or die('Non posso caricare il file');
echo "L'immagine è stata ridimensionata ed inserita con successo:
<img src=\"$cartella_thumbs/$nome_file\" />
";
echo "continua ad:
";
}
?>
<html>
<head>
<title>Image Report</title>
<script language="JavaScript">
<!--
function FP_changeProp() {//v1.0
var args=arguments,d=document,i,j,id=args[0],o=FP_getObjectByID(id),s,ao,v,x;
d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o";
ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) {
s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
if(s) eval(s+"=v"); }
}
function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}
function FP_changePropRestore() {//v1.0
var d=document,x; if(d.$cpe) { for(i=0; i<d.$cpe.length; i++) { x=d.$cpe[i];
if(x.v=="") x.v=""; eval("x."+x.n+"=x.v"); } d.$cpe=null; }
}
// -->
</script>
</head>
<body>
<font face="Verdana">[b]
<a href="http://www.freestylepark.it/public/upload/INDEX-UPLOAD.htm">
<font size="2" color="#808080">
<span style="text-decoration: none" id="id1" onmouseout="FP_changePropRestore()" onmouseover="FP_changeProp(/*id*/'id1',1,'style.backgroundColor','#FFFF00')">1>INSERIRE ALTRE FOTO</span></font></a><font size="2">
<font color="#808080"></font><a href="http://www.freestylepark.it/public/foto/index.php">
<font color="#808080">
<span style="text-decoration: none" id="id2" onmouseout="FP_changePropRestore()" onmouseover="FP_changeProp(/*id*/'id2',1,'style.backgroundColor','#FFFF00')">2>GUARDA TUTTE LE FOTO INSERITE</span></font></a><font color="#808080">
</font></font>[/b]</font></p>
<body>
<html>