Originariamente inviato da telegio
devi creare un campo di tipo file chiamato image
prova perchè l'ho corretto a mano...
Non va!
I dati vengono inviati tutti tranne l'immagine.
Non c'è nessun riferimento nel campo del DB ne
il file nella cartella images (quella dove dovrebbe essere spostata).
Questo è il codice completo della pagina.
Codice PHP:
<?php
include("dati.php");
$link=mysql_connect("$db_host","$db_login","$db_pass")
or die ("Non riesco a connettermi a [b]$db_host");
@mysql_select_db ($database, $link)
or die ("Non riesco a selezionare il db $database
");
if (isset($_REQUEST['nome'])){
// upload dell'immagine di sfondo
$abpath = "C:\Programmi\EasyPHP1-7\www\provalez\images";
if(!is_dir($abpath))
{
mkdir($abpath, 0755);
$dir_ID=$abpath."
";
}
$sizelim = "yes"; // qui puoi dare un limite alla grandezza dell'immagine..
$size = "66560";
$tipo1 = "image/pjpeg"; //Jpeg tipo 1
$tipo2 = "image/jpeg"; //Jpeg tipo 2 puoi aggiungerne altri ma sotto devi mettere gli if relativi
if ($_FILES['image']['name'] != "")
{
$uploadfile = $abpath."/".$_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile);
}
if ($_FILES['image']['name'] == "") {
$logfoto1= "<td colspan=\"3\" class=\"style5\"> </td>";
}
if ($_FILES['image']['name'] != "")
{
if ($sizelim == "yes")
{
if ($_FILES['image']['size'] > $size)
{
$logfoto1= "<td colspan=\"3\" class=\"warnings\">The file size is too big</td>";
}else{
if (($_FILES['image']['type'] == $tipo1)or ($_FILES['image']['type'] == $tipo2))
{
$uploadfile = $abpath."/". $_FILES['image']['name'];
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile))
{
$logfoto1= "<td colspan=\"3\" class=\"style5\">file uploaded succesfully</td>";
}
else {$logfoto1= "<td colspan=\"3\" class=\"style5\">file not uploaded </td>";}
} else {$logfoto1="<td colspan=\"3\" class=\"warnings\">The file doesn't seems to be an image</td>";}
}}}
$dati=" INSERT INTO rubrica VALUES (NULL,
'".$_REQUEST['nome']."',
'".$_REQUEST['cognome']."',
'".$_REQUEST['reparto']."',
'".$_REQUEST['stipendio']."',
'".$_FILES['image']['name']."'
)";
mysql_query ($dati, $link)
or die ("Non riesco ad eseguire la query $dati");
Echo "I Dati sono stati archiviati con successo nel DataBase $database";
mysql_close ($link);
echo "<meta http-equiv=refresh content=3;url=$PATH_INFO>";
}
?>
<?php echo $logfoto1 ?>
<html>
<head>
<title>Form dati</title>
</head>
<body>
<TABLE border=0 width=100% cellpadding=3>
<tr>
<td width=100% colspan=2>
<p align=center>[b]Inserisci i dati del nuovo utente
<form method=POST action=<? $PATH_INFO ?>>
[/b]</td>
</tr>
<tr>
<td width=18%>[b]Nome[/b]</td>
<td width=82%><input type=text name=nome size=20></td>
</tr>
<tr>
<td width=18%>[b]Cognome[/b]</td>
<td width=82%><input type=text name=cognome size=20></td>
</tr>
<tr>
<td width=18%>[b]Reparto[/b]</td>
<td width=82%><input type=text name=reparto size=20></td>
</tr>
<tr>
<td width=18%>[b]Stipendio[/b]</td>
<td width=82%><input type=text name=stipendio size=20></td>
</tr>
<tr>
<td width=18%>[b]Foto[/b]</td>
<td width=82%><input type=file name=image size=20></td>
</tr>
<tr>
<td width=18%>[b]<input type=submit value=Inserisci nuovi dati>[/b]</td>
<td width=82%></form></td>
</tr>
</table>
</body>
</html>
Fammi sapere, ok? Grazie.
Ps: io ho un altro codice che funziona ma ricevo alla fine dei messaggi warning che
non ho capito a cosa si riferiscono e come risolvere la cosa..magari se ti, ti va sottopongo
quello.