codice:
<?php
include "auth.php";
require "../dbconn.php";
if(($_POST))
{
if (isset($_POST['artista'])) {$artista = htmlspecialchars($_POST['artista']);} else { $artista = "";}
if (isset($_POST['titolo'])) {$titolo = htmlspecialchars($_POST['titolo']);} else { $titolo = "";}
if (isset($_POST['prezzo'])) {$prezzo = htmlspecialchars($_POST['prezzo']);} else { $prezzo = "";}
if (isset($_POST['quant'])) {$quant = htmlspecialchars($_POST['quant']);} else { $quant = "";}
$_SESSION['quant'] = $quant;
$_SESSION['artista'] = $artista;
$_SESSION['titolo'] = $titolo;
$_SESSION['prezzo'] = $prezzo;
$tipo = htmlspecialchars($_POST['tipo']);
$data = date("Y-m-d");
$ERRORA = "";
// CONTROLLO DATI INSERITI //
if ((!is_numeric($quant)) || ($quant == ""))
{
$_SESSION['quant_errore'] = true;
$ERRORA = 1;
}
if ((!is_numeric($prezzo)) || ($prezzo == ""))
{
$_SESSION['prezzo_errore'] = true;
$ERRORA = 1;
}
if ($artista == "")
{
$_SESSION['artista_errore'] = true;
$ERRORA = 1;
}
if ($titolo == "")
{
$_SESSION['titolo_errore'] = true;
$ERRORA = 1;
}
$foto1 = "";
if ($ERRORA == 1)
{
$_SESSION['erroreA'] = true;
}
else
{
if(is_uploaded_file($_FILES['image_filename1']['tmp_name'])) {
$foto1 = gestisci_upload(1);
}
$data = date("Y-m-d");
$desc = $_POST['descrizione'];
$_SESSION['erroreA'] = false;
$artista = mysql_real_escape_string($artista);
$prezzo = mysql_real_escape_string($prezzo);
$data = mysql_real_escape_string($data);
$tipo = mysql_real_escape_string($tipo);
$quant = mysql_real_escape_string($quant);
$titolo = mysql_real_escape_string($titolo);
//DESCRIZIONE NEL COMMENTO
// desc = '$desc',
$query = "INSERT INTO products
set nomeartista = '$artista',
prezzo = $prezzo,
data = '$data',
titolo = '$titolo',
tipo = '$tipo',
desc = '$desc',
quant = $quant,
foto = '$foto1'";
$result = mysql_query($query)
or die (mysql_error());
}
}
else
{
echo "";
}
/*if (isset($_POST))
{
$query = "INSERT INTO clienti
(nome,cognome,indirizzo,citta,stato,cap,telefono,email,passw,nick,data)
VALUES(
'$nome',
'$cognome',
'$indirizzo',
'$citta',
'$stato',
'$cap',
'$telefono',
'$email',
'$pass',
'$nick',
'$data')";
$result = mysql_query($query)
or die (mysql_error());
}*/
function gestisci_upload(){
$sFilename = "image";
// gestisco l'upload della foto
$tipi_supportati = array('1','2','3'); //'.gif','.jpeg','.png'
list($width, $height, $type, $attr) = getimagesize($_FILES[$sFilename]['tmp_name']);
if ($type == 1) {
$source = imagecreatefromgif($_FILES[$sFilename]['tmp_name']);
} elseif ($type == 2) {
$source = imagecreatefromjpeg($_FILES[$sFilename]['tmp_name']);
} elseif ($type == 3) {
$source = imagecreatefrompng($_FILES[$sFilename]['tmp_name']);
} else {
//$CONTENT .= "<div style=\"color:red;\">Formato immagine non supportato</div>";
return;
}
$time = time();
$imgfile = "../upload/".$time."_".$num.".jpg";
$thumbfile = "../upload/thumbs/".$time."_".$num.".jpg";
$ratio = ($width/200 >= $height/200) ? 200 / $width : 200 / $height;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
//$temp = imagecreatetruecolor($newwidth, $newheight);
$temp = imagecreatetruecolor(200, 200);
$background = imagecolorallocate($temp, 250, 240, 213);
imagefilledrectangle($temp, 0, 0, 200, 200, $background);
imagecopyresampled($temp, $source, (100-$newwidth/2), (100-$newheight/2), 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($temp,$thumbfile,90);
// faccio la grande
if ($width <= 500) {
$temp = imagecreatetruecolor($width, $height);
imagefilledrectangle($temp, 0, 0, $width, $height, $background);
imagecopyresampled($temp, $source, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($temp,$imgfile,90);
} else {
$ratio = 500/$width;
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
$temp = imagecreatetruecolor($newwidth, $newheight);
imagefilledrectangle($temp, 0, 0, $newwidth, $newheight, $background);
imagecopyresampled($temp, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($temp,$imgfile,90);
}
fclose($image);
return $time."_".$num;
}
?>
[