Inserimento dell'immagine:
Codice PHP:
<?php include('controllologin.php');?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Inserimento Immagini</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stiletesto.css" rel="stylesheet" type="text/css">
</head>
<body>
<table  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="row">[img]../img/paint_application.png[/img]</th>
    <td><h1>Inserimento Immagini </h1></td>
  </tr>
</table>

<form action="upload.php" method="post" enctype="multipart/form-data">
<table  border="0" cellspacing="2" cellpadding="0">
  <tr>
    <th scope="row"><div align="right">Seleziona Immagine</div></th>
    <td><input name="image" type="file" /></td>
  </tr>
  <tr>
    <td></td>
    <td><input name="upload" type="submit" class="bottone" value="Carica immagine" /></td>
  </tr>
</table>
   
</form>
<a href="home.php">[img]../img/tools_small.png[/img]

back</a>
</body>
</html>
file upload.php:
Codice PHP:
<?php
include('../connessione.php');
$msg "";
do {
  if (
is_uploaded_file($_FILES['image']['tmp_name'])) {
    
// Controllo che il file non superi i 18 KB
    
if ($_FILES['image']['size'] > 130000) {
      
$msg "

Il file non deve superare i 128 kb</p>"
;
      break;
    }
    
// Ottengo le informazioni sull'immagine
    /*open_basedir = "/var/tmp/";
    list($width, $height, $type, $attr) = getimagesize($_FILES['image']['tmp_name']);
    // Controllo che le dimensioni (in pixel) non superino 160x180
    if (($width > 280) || ($height > 500)) {
      $msg = "

Dimensioni non corrette</p>";
      break;
    }
    // Controllo che il file sia in uno dei formati GIF, JPG o PNG
    if (($type!=1) && ($type!=2) && ($type!=3)) {
      $msg = "

Formato non corretto</p>";
      break;
    }*/
    // Verifico che sul sul server non esista già un file con lo stesso nome
    // In alternativa potrei dare io un nome che sia funzione della data e dell'ora
    
if (file_exists('upload_img/'.$_FILES['image']['name'])) {
      
$msg "

File già esistente sul server. Rinominarlo e riprovare.</p>"
;
      break;
    }
    
// Sposto il file nella cartella da me desiderata
    
if(!move_uploaded_file($_FILES['image']['tmp_name'],'upload_img/'.$_FILES['image']['name'])){
      
$msg "

Errore nel caricamento dell'immagine</p>"
;
      break;
    } 
    else{
     
$msg"

Operazione Eseguita</p>"
;
     break;
     }
  }
} while (
false);

if(
$msg!=""){
    
$sql="INSERT INTO immagini (nome) VALUES ('".$_FILES['image']['name']."')";
    
mysql_db_query($nomedb,$sql);
    
$msg "<h2>Immagine caricata nel server</h2>";
    }
else{
    
$msg "

Nessuma immagine Selezionata</p>"
;
    }
?>