Eccolo:
Codice PHP:
$cert1 = "image/jpeg"; //Jpeg
$cert2 = "image/gif"; //Gif
$cert3 = "image/bmp"; //Bmp
$cert4 = "image/pjpeg"; //Pjpg
//questo serve per fare il calcolo in KB delle img
$g = $_FILES['imagefile']['size'];
$g2 = 1024;
$g3 = $g / $g2;
$g4 = round($g3);
$g5 = $g4;
$h = $_FILES['imagefile2']['size'];
$h2 = 1024;
$h3 = $h / $h2;
$h4 = round($h3);
$h5 = $h4;
$f = $_FILES['imagefile3']['size'];
$f2 = 1024;
$f3 = $f / $f2;
$f4 = round($f3);
$f5 = $f4;
// i dati vengono mandati tramite form
if ($_POST["action"] == "post") {
######################################### controllo foto UNO ########################################
list($width, $height, $type, $attr) = getimagesize($_FILES["imagefile"]["tmp_name"]);
if ($width <= 400 && $height <= 500){
$send1 = true;
}else{
$send1 = false;
echo "<FONT COLOR=\"#FF0000\">Errore foto</font><FONT COLOR=\"#339933\"> ".$_FILES["imagefile"]["name"]."</font>
<FONT COLOR=\"#3300CC\">Larghezza: [b]$width[/b]
Aaltezza: [b]$height[/b]</FONT>
Massimo consentito [b]400[/b]x[b]500 pixel[/b]
";
}
if ($_FILES['imagefile']['size'] <= "30720"){
$send2 = true;
}
else
{
$send2 = false;
echo "<FONT COLOR=\"#FF0000\">Errore foto</font><FONT COLOR=\"#339933\"> ".$_FILES["imagefile"]["name"]."</font>
Pesa [b]".$g5." [/b]kb
Massimo consentito [b]30 kb[/b]</font>
";
}
if (($_FILES['imagefile']['type'] == $cert1) or ($_FILES['imagefile']['type'] == $cert2) or ($_FILES['imagefile']['type'] == $cert3) or ($_FILES['imagefile']['type'] == $cert4)) {
$send3 = true;
}
else
{
$send3 = false;
if($imagefile != ""){
echo "<div align=\"center\"><FONT SIZE=\"-1\" COLOR=\"#FF0000\">L'estensione del file <FONT COLOR=\"#330099\">[B]".$_FILES["imagefile"]["name"]."[/B]</FONT> non è valida
<FONT SIZE=\"1\" COLOR=\"#515151\">Può essere BMP, JPG oppure GIF</FONT>
</div>";
}
}
######################################### controllo foto DUE 2 ########################################
if ($imagefile2 != ""){
list($width, $height, $type, $attr) = getimagesize($_FILES["imagefile2"]["tmp_name"]);
if ($width <= 400 && $height <= 500){
$send1 = true;
}else{
$send1 = false;
echo "<FONT COLOR=\"#FF0000\">Errore foto</font><FONT COLOR=\"#339933\"> ".$_FILES["imagefile2"]["name"]."</font>
<FONT COLOR=\"#3300CC\">Larghezza: [b]$width[/b]
Aaltezza: [b]$height[/b]</FONT>
Massimo consentito [b]400[/b]x[b]500 pixel[/b]
";
}
if ($_FILES['imagefile2']['size'] <= "30720"){
$send2 = true;
}
else
{
$send2 = false;
echo "<FONT COLOR=\"#FF0000\">Errore foto</font><FONT COLOR=\"#339933\"> ".$_FILES["imagefile2"]["name"]."</font>
Pesa [b]".$h5." [/b]kb
Massimo consentito [b]30 kb[/b]</font>
";
}
if (($_FILES['imagefile2']['type'] == $cert1) or ($_FILES['imagefile2']['type'] == $cert2) or ($_FILES['imagefile2']['type'] == $cert3) or ($_FILES['imagefile2']['type'] == $cert4)) {
$send3 = true;
}
else
{
echo "<div align=\"center\"><FONT SIZE=\"-1\" COLOR=\"#FF0000\">L'estensione del file <FONT COLOR=\"#330099\">[B]".$_FILES["imagefile2"]["name"]."[/B]</FONT> non è valida
<FONT SIZE=\"1\" COLOR=\"#515151\">Può essere BMP, JPG oppure GIF</FONT>
</div>";
$send3 = false;
}
// se imagifile2 è pieno o vuoto
}
######################################### controllo foto TRE 3 ########################################
if ($imagefile3 != ""){
list($width, $height, $type, $attr) = getimagesize($_FILES["imagefile3"]["tmp_name"]);
if ($width <= 400 && $height <= 500){
$send1 = true;
}else{
$send1 = false;
echo "<FONT COLOR=\"#FF0000\">Errore foto</font><FONT COLOR=\"#339933\"> ".$_FILES["imagefile3"]["name"]."</font>
<FONT COLOR=\"#3300CC\">Larghezza: [b]$width[/b]
Aaltezza: [b]$height[/b]</FONT>
Massimo consentito [b]400[/b]x[b]500 pixel[/b]
";
}
if ($_FILES['imagefile3']['size'] <= "30720"){
$send2 = true;
}
else
{
$send2 = false;
echo "<FONT COLOR=\"#FF0000\">Errore foto</font><FONT COLOR=\"#339933\"> ".$_FILES["imagefile3"]["name"]."</font>
Pesa [b]".$f5." [/b]kb
Massimo consentito [b]30 kb[/b]</font>
";
}
if (($_FILES['imagefile3']['type'] == $cert1) or ($_FILES['imagefile3']['type'] == $cert2) or ($_FILES['imagefile3']['type'] == $cert3) or ($_FILES['imagefile3']['type'] == $cert4)) {
$send3 = true;
}
else
{
echo "<div align=\"center\"><FONT SIZE=\"-1\" COLOR=\"#FF0000\">L'estensione del file <FONT COLOR=\"#330099\">[B]".$_FILES["imagefile3"]["name"]."[/B]</FONT> non è valida
<FONT SIZE=\"1\" COLOR=\"#515151\">Può essere BMP, JPG oppure GIF</FONT>
</div>";
$send3 = false;
}
// se imagifile3 è pieno o vuoto
}
############################################## FINE CONTROLLI #####################################
if (($send1 == true) && ($send2 == true)&& ($send3 == true)){
$send = true;}
else{
$send = false;}
if($send == true){
echo "ok le foto vanno bene";
copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])
or die ("<FONT SIZE=\"-1\" COLOR=\"#FF0000\">Almeno una foto
</font>
<a href=javascript:history.back()>Torna e correggi</a>
");
copy ($_FILES['imagefile2']['tmp_name'], "files/".$_FILES['imagefile2']['name']);
copy ($_FILES['imagefile3']['tmp_name'], "files/".$_FILES['imagefile3']['name']) ;
}
else{
echo " le foto sono invalide <a href=javascript:history.back()>Torna e correggi</a>";
}
questo per le img ke vengono mandate tramite form la prima img si kima:
imagefile
la seconda:
imagefile2
la terza:
imagefile3
se vuoi inserire dei dati nel db al controllo ke $send==true){
ci metti la connessione al db e l'inserimento dei dati, io ho fatto cosi ora ti ho postato solo la parte per le img xke il tutto è un po lunghino e cmq è xsonalizzato alle mie esigenze, con poco dovresti riuscire a personalizzartelo.
Ultima cosa le img nel mio caso le salvo in una cartella kiamata "files", imposta tu la cartella ke vuoi nella stringa
Codice PHP:
copy ($_FILES['imagefile2']['tmp_name'], "files/".$_FILES['imagefile2']['name']);