Codice PHP:
<?php
//settaggio del fuso corretto
//date_default_timezone_set('Europe/Rome');
if(isset($_POST['immobile'])){
$immobile = $_POST['immobile'];
//$immobile = addslashes(filter_var($_POST['immobile'], FILTER_SANITIZE_STRING));
}
if(isset($_POST['ubicazione'])){
$ubicazione = $_POST['ubicazione'];
//$ubicazione = addslashes(filter_var($_POST['ubicazione'], FILTER_SANITIZE_STRING));
}
if(isset($_POST['superfice'])){
$sup = $_POST['superfice'];
//$sup = addslashes(filter_var($_POST['superfice'], FILTER_SANITIZE_STRING));
}
//verifico le variabili
echo $sup;
echo $immobile;
echo $ubicazione;
// upload the file
if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {
// file needs to be jpg,gif,bmp,x-png and 1 MB max
if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 1000000))
{
//alcuni settings
$max_upload_width = 500;
$max_upload_height = 380;
$max_width_box = 500;
$max_height_box = 380;
// if user chosed properly then scale down the image according to user preferances
if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){
$max_upload_width = $_REQUEST['max_width_box'];
}
if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){
$max_upload_height = $_REQUEST['max_height_box'];
}
// if uploaded image was JPG/JPEG
if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){
$image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was GIF
if($_FILES["image_upload_box"]["type"] == "image/gif"){
$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
}
// BMP doesn't seem to be supported so remove it form above image type test (reject bmps)
// if uploaded image was BMP
if($_FILES["image_upload_box"]["type"] == "image/bmp"){
$image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was PNG
if($_FILES["image_upload_box"]["type"] == "image/x-png"){
$image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
}
$remote_file = "images/facebook_immobiliare/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file,90);
chmod($remote_file,0644);
// ottengo le dimensioni originali dell'immagine width ed height
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$max_upload_width || $image_height >$max_upload_height){
$proportions = $image_width/$image_height;
if($image_width>$image_height){
$new_width = $max_upload_width;
$new_height = round($max_upload_width/$proportions);
}
else{
$new_height = $max_upload_height;
$new_width = round($max_upload_height*$proportions);
}
//creo l'immagine temporanea di dimensione corretta
$new_image = imagecreatetruecolor($new_width , $new_height);
//recupero l'immagine temporanea
$image_source = imagecreatefromjpeg($remote_file);
//creo una copia dell'originale con i nuovi parametri di dimendione
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
//salvo l'immagine comprimendola
imagejpeg($new_image,$remote_file,90);
imagedestroy($new_image);
}
imagedestroy($image_source);
header("Location: inserimento2.php?upload_message=immagine inserita&upload_message_type=success&show_image=".$_FILES["image_upload_box"]["name"]);
exit;
}
else{
header("Location: inserimento2.php?upload_message=controlla che il formato della foto sia jpg, gif o png e non piu di 1MB&upload_message_type=error");
exit;
}
include_once 'core/config.php';
include_once 'core/My_fb.php';
include_once 'core/image_resize.php';
//connessione mysql
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Connessione fallita: ' . mysql_error());
//Selezione del db
$db = @mysql_select_db(DB_DATABASE, $link)or die('Selezione DB fallita: ' . mysql_error());
//parametri per la query per inserimento immagini
$t1 = " images "; # nome della tabella
$v1 = array ('','','',''); # valori da inserire
$r1 = "id,name,tipo,images"; # campi da popolare
// chiamata alla funzione per l'inserimento dei dati
$data = inserisci($t1,$v1,$r1);
//parametri per la query per post agenzia
$t = " listings "; # nome della tabella
$v = array ('3','','',$sup,$ubicazione,'2','','','','','','','',date("Y-m-d"),$immobile); # valori da inserire
$r = "agencies,contract,prize,sqm,locate,foto,rooms,bathrooms,heating,box_car,garden,balcone_terrazza,id,date,title"; # campi da popolare
// chiamata alla funzione per l'inserimento dei dati
$data1 = inserisci($t,$v,$r);
//echo "<script>location='insert_ok.php';</script>";
mysql_close($link);
}//fine controllo submit