ciao a tutti problemino ho un manuale di mysql e php e c'è un paragrafo riguardante l'upload di immagini nel server e i vari dati in mysql. allora
form per invio in html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
</head>
<body>
<form name="form1" method="post" action="check_image.php" enctype="multipart/form-data">
<table border="0" cellpadding="5">
<tr>
<td>image title or caption
example: you talkin to me?</td>
<td><input name="image_captio" type="text" id="item_caption" size="55" maxlength="255" /></td>
</tr>
<tr>
<td>your username</td>
<td><input name="image_username" type="text" id="image_username" size="55" maxlength="255" /></td>
</tr>
<tr>
<td>upload image:</td>
<td><input name="image_filename" type="file" id="image_filename" /></td>
</tr>
</table>
acceptable imae formate include:GIF, JPG/JPEG, and PNG.
<p align="center"><input type="submit" name="submit" value="submit" />
<input type="reset" name="submit2" value="clear form" />
</p>
</form>
</body>
</html>
questo è il codice con cui ho creato la tabella che ha creato correttamente.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
</head>
<?php
$link=mysql_connect("localhost","root","roberto280 581")
or die(mysql_error());
echo "<h4>CONNESSIONE EFFETTUATA CON SUCCESSO.</h4>
";
mysql_select_db("moviesite", $link)
or die(mysql_error());
echo "
DATABASE SELEZIONATO CON SUCCESSO</p>
";
$sql="CREATE TABLE IF NOT EXISTS images(
image_id INT(11) NOT NULL AUTO_INCREMENT,
image_caption VARCHAR(255) NOT NULL,
image_username VARCHAR(255) NOT NULL,
image_date DATE NOT NULL,
PRIMARY KEY(image_id)
)";
$result=mysql_query($sql)
or die(mysql_error());
echo "tabella creata con successo.";
?>
<body>
</body>
</html>
e questo il file che dovrebbe uplodare le immagini
<?php
//si connette al database
$link=mysql_connect("localhost","root","roberto280 581")
or die(mysql_error());
mysql_select_db("moviesite", $link)
or die(mysql_error());
//rende disponibile le variabili
$image_caption=$_POST['image_caption'];
$image_username=$_POST['image_username'];
$image_tempname=$_FILES['image_filename']['name'];
$today=date("Y-m-d");
$imageDir="C:/Programmi/Apache Group/Apache2\htdocs/websolutionportal/upload/images/";
$imageName= $imageDir . $image_tempname;
//carical'immagine e verifica il tipo di immagine
//il percorso deve conicidere con le direcotry dellle immagini
if(move_uploaded_file($_FILES['image_filename']['tmp_name'],$image_name)) {
//acquisisce informazioni sull'immagine che si sta caricando
list($width,$height,$type,$attr)=getimagesize($ima geName);
switch($type) {
case 1:
$ext=".gif";
break;
case 2:
$ext=".jpg";
break;
case 3:
$ext=".png";
break;
default:
echo "sorr, but the file you uploadd wa not a GIF, JPG, or".
"PNG file.
";
echo "Please hit your browser back button and try again.";
}
//inserisce le informazioni nella tabella delle immagini
$insert="INSERT INTO images
(images_caption, image_username, image_date)
VALUES
('$image_caption','$image_username','$today')";
$insertresults=mysql_query($insert)
or die(mysql_error());
$lastpicid=mysql_insert_id();
$newfilename= $imageDir . $lastpicid . $ext;
rename($imagenName,$newfilename);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
</head>
<body>
<h1>so how does it feel to be famous?</h1>
here is the picture you just uploaded to our servers:</p>
[img]images/<?php echo $lastpicid. $ext;?>[/img]
<?php echo $image_name;?>
this image is a<?php echo $ext; ?>image
it is <?php echo $width; ?>pixels wide
and <?php echo $height; ?>pixels hig.
it was uploaded on <?php echo $today;?>.
</body>
</html>
questo è l'errore che segue
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\TEMP\php302.tmp' to '' in C:\Programmi\Apache Group\Apache2\htdocs\websolutionportal\upload\chec k_image.php on line 16
datemi una mano vi prego......grazie!

Rispondi quotando