Ciao allora:
creai un tabella con:
id,campo1,campo2,foto
i campi1 etc.. sono quelli che devi scegliere tu!
<form method="post" action="<? $PHP_SELF ?>" name="formData" enctype="multipart/form-data">
<input type="hidden" name="op" value="mod">
<label for="firstname" accesskey="f" class="testo2">Nome:</label>
<input type="text" name="titolo" maxlength="20">
<label for="firstname" accesskey="f" class="testo2">Descrizione:</label>
<textarea name="testo" cols="40" rows="10" wrap="soft" onKeyUp="contatore(this.form)"></textarea>
<label for="firstname" accesskey="f" class="testo2">Foto:</label>
<input type="file" name="foto1">
<input id="button" type="submit" value="Inserisci"/>
</form>
Codice PHP:
<?
if($_POST['op']=="mod"){
//cattura i dati dal modulo
$titolo=$_POST['titolo'];
$titolo= addslashes($titolo);
$testo=$_POST['testo'];
$testo= addslashes($testo);
$foto1=$_POST['foto1'];
$a=rand(1, 9);
$b=rand(1, 9);
$c=rand(1, 9);
$d=rand(1, 9);
$e=rand(1, 9);
$f=rand(1, 9);
$ante=$a.$b.$c.$d.$e.$f;
//immagine principale
$uploaddir = "./uploads/";
$uploadfile = $ante .$_FILES['foto1']['name'];
$uploadfile1 = $uploaddir .$ante .$_FILES['foto1']['name'];
$time=time();
if (move_uploaded_file($_FILES['foto1']['tmp_name'], $uploadfile1)) {
print "$uploadfile1 Allegato was successfully uploaded. ";
} else {
print "$uploadfile1 Possible file upload attack! Here's some debugging info:\n";
}
$result = mysql_query ("insert into tua_tabella(foto,campo1,campo2) values('$uploadfile1','$titolo','$testo')");
}
?>
ah dimenticavo nella stessa directory crea una carte chiamata "uploads".