= 2 If ($nickname == ""){ $errore = $ERR_NONICK; } elseif(strlen($nickname)<2){ $errore = $ERR_NOVALIDNICK; } // Verifica del campo attribute name if ($errore == $NOERR) { if(strlen($profilo)==3 && (substr($profilo,0,1)=="f" || substr($profilo,0,1)=="a" || substr($profilo,0,1)=="v") && is_numeric(substr($profilo,-2))){ if(substr($profilo,0,1)=="a"){ $tipofile=1; } elseif(substr($profilo,0,1)=="v"){ $tipofile=2; } } else $errore = $ERR_NOVALIDTYPE; } // Controllo del checksum MD5 del nickname if ($errore == $NOERR && $controllochk) { if($chk == ""){ $errore=$ERR_CHK; // decommentare in seguito }else{ $salt=substr($chk,0,8); $contr= (md5($nickname.$salt,false)); if ($salt.$contr != $chk) $errore=$ERR_MD5; } } // Controllo il file che è ststo inviato if ($errore == $NOERR) { if (!is_file($_FILES['file']['tmp_name'])) { $errore = $ERR_NO_FILE; } else { $estensione = get_extension($_FILES['file']['name']); if($estensione == ""){ $errore=$ERR_NO_EXT; } else { $trovato = false; for ($ne = 0; $ne < $NUMEXT[$tipofile]; $ne++ ) { if ($estensione == $ESTENSIONI[$tipofile][$ne]) { $trovato = true; } } if ($trovato == false) { $errore = $ERR_EXT; } else { if ($_FILES['file']['size'] == 0 || $_FILES['file']['size'] > $MAXDIM[$tipofile]) { $errore = $ERR_DIM; } } } } } // Inizio a processare i files inviati if ($errore == $NOERR) { // Creo la struttura di directory ed il percorso del file $outpath = "$PATH_MEDIA/$community"; if(!is_dir($outpath)) mkdir($outpath, 0777); $outpath = $outpath . "/" . $nickname{0}; if(!is_dir($outpath)) mkdir($outpath, 0777); $outpath = $outpath . "/" . substr($nickname , -2); if(!is_dir($outpath)) mkdir($outpath, 0777); $outpath = $outpath . "/" . $nickname; if(!is_dir($outpath)) mkdir($outpath, 0777); $outpath = $outpath . "/" . $nickname . ","; $outfile = $outpath . $profilo . "." . $estensione; // Copia del file if (copy($_FILES[file][tmp_name] , $outfile ) ) { // Creazione dei ThumbNail if ($tipofile == 0) { //creaThumb($profilo,$outpath,$estensione,$TQUALITY) $resp_convert = creaThumb($profilo,$outpath,$estensione,$TQUALITY); if($resp_convert != ""){ $errore = "499 ERROR in thumb-creation: ".$resp_convert; } } // Creo il file HTML // Inizio a processare i files inviati if ($errore == $NOERR) { make_html("$outpath$profilo.html","http://$NOME_HOST/contenuti/$nickname,$profilo.$estensione"); }else{ // da gestire la cancellazione del file } // Cancella eventuali versioni obsolete del file for ($ne = 0; $ne < $NUMEXT[$tipofile]; $ne++ ) { if ($ESTENSIONI[$tipofile][$ne] != $estensione and is_file($outpath . $profilo . "." . $ESTENSIONI[$tipofile][$ne])) { unlink($outpath . $profilo . "." . $ESTENSIONI[$tipofile][$ne]); } } } else { $errore = $ERR_UPLOAD; } if($mustcomp) compatta_foto($outpath); } // comunicazione con il profile manager if ($errore == $NOERR && $notifypm){ $nick=urlencode($nickname); $community=strtoupper($community); if($tipofile == 0){ //foto $numfoto=conta_foto($outpath); $sFile = file_get_contents("$URL_PMFOTO?nickname=$nick&comunita=$community&numerofoto=$numfoto"); error_log("$URL_PMFOTO?nickname=$nick&comunita=$community&numerofoto=$numfoto
"); }else{ //audio o video $filename = urlencode("/contenuti/$nickname,$profilo.$estensione"); if($tipofile == 1){ $nomeattributo="audio"; }else{ $nomeattributo="video"; } $sFile = file_get_contents("$URL_PMAV?nickname=$nick&comunita=$community&nomeattributo=$nomeattributo&valoreattributo=$filename&cmd=set"); error_log("$URL_PMAV?nickname=$nick&comunita=$community&nomeattributo=$nomeattributo&valoreattributo=$filename&cmd=set
"); } if($sFile){ if(strlen($sFile)>2){ if(substr($sFile,0,3)!="200") $errore = $ERR_PM3; }else{ $errore = $ERR_PM2; } }else{ $errore = $ERR_PM1; } } // Stampa a video del risultato dell'operazione //if ($errore != $NOERR){ error_log("UPLOAD: ".$nickname." ".$errore); // } echo $errore; exit; function creaThumb($profilo,$outpath,$estensione,$TQUALITY){ // Creazione dei ThumbNail $outfile = $outpath . $profilo . "." . $estensione; $numero=substr($profilo , -2); $thumbfile = $outpath . "n" . $numero . ".jpg"; $esegui="convert -colorspace RGB -quality " . $TQUALITY . " " . $outfile . "[0] " . $thumbfile ." 2>&1"; $rr= exec($esegui); $thumbfile = $outpath . "i" . $numero . ".jpg"; $esegui="convert -colorspace RGB -quality " . $TQUALITY . " -geometry 64x64 " . $outfile . "[0] " . $thumbfile; $rr= $rr . exec($esegui); $thumbfile = $outpath . "c" . $numero . ".jpg"; $esegui="convert " . $outfile . "[0] -colorspace RGB -quality " . $TQUALITY . " -resize x64 -resize \"64x<\" -resize 50% -gravity center -crop 32x32+0+0 +repage " . $thumbfile ; $rr= $rr . exec($esegui,$aaa,$bbb); $thumbfile = $outpath . "t" . $numero . ".jpg"; $esegui="convert -colorspace RGB -quality " . $TQUALITY . " -geometry 160x160 " . $outfile . "[0] " . $thumbfile; $rr= $rr . exec($esegui); return $rr; } // funzione per estrarre l'estensione del nome del file function get_extension($filename){ $estensione = ""; if(strlen($filename)>4 && substr(substr($filename,-5),0,1) == ".") $estensione=substr($filename,-4); if(strlen($filename)>3 && substr(substr($filename,-4),0,1) == ".") $estensione=substr($filename,-3); if(strlen($filename)>2 && substr(substr($filename,-3),0,1) == ".") $estensione=substr($filename,-2); return strtolower($estensione); } // funzione per la "compattazione" delle foto function compatta_foto($uri) { $maxfoto = 6; $firstempty = 0; global $NUMEXT; global $ESTENSIONI; global $NOME_HOST; global $nickname; for ($co=0; $co<($maxfoto); $co++) { if (is_file($uri."f0".$co.".html")){ if ($firstempty < $co){ //sposta unlink($uri."f0".$co.".html"); for ($ne = 0; $ne < $NUMEXT[0]; $ne++ ) { if(is_file($uri."f0".$co.".".$ESTENSIONI[0][$ne])){ rename($uri."f0".$co.".".$ESTENSIONI[0][$ne],$uri."f0".$firstempty.".".$ESTENSIONI[0][$ne]); make_html($uri."f0".$firstempty.".html","http://$NOME_HOST/contenuti/$nickname,f0$firstempty.".$ESTENSIONI[0][$ne]); } } if(is_file($uri."i0".$co.".jpg")) rename($uri."i0".$co.".jpg",$uri."i0".$firstempty.".jpg"); if(is_file($uri."t0".$co.".jpg")) rename($uri."t0".$co.".jpg",$uri."t0".$firstempty.".jpg"); if(is_file($uri."c0".$co.".jpg")) rename($uri."c0".$co.".jpg",$uri."c0".$firstempty.".jpg"); if(is_file($uri."n0".$co.".jpg")) rename($uri."n0".$co.".jpg",$uri."n0".$firstempty.".jpg"); } $firstempty++; }else{ // da gestire la rimozione di sporcizia (non esiste l'html ma magari ci sono le imgs) } } return true; } //funzione per creare i files html di reindirizzamento function make_html($file,$url){ $fileout=fopen ($file ,"w"); if($fileout) { fwrite($fileout,"\n"); fwrite($fileout,"\n"); fwrite($fileout,"\n"); fwrite($fileout,""); fclose($fileout); return true; } return false; } // funzione per la contare delle foto function conta_foto($uri) { $maxfoto = 6; $numfoto = 0; for ($co=0; $co<($maxfoto); $co++) { if (is_file($uri."f0".$co.".html")){ $numfoto++; } } return $numfoto; } ?>