- 一切正常,但出现此错误
Notice: Undefined index: image in C:\wamp\www\neos-final\update-image.php on line 21
- 第 21 行是
$image=$_FILES['image']['name'];
这条线怎么办:(
<form action="" method="post" enctype="multipart/form-data"> <input type="file" name="image" id="image" size="40"> <input name="" type="submit" value="upload" /> </form> <?php $con = mysql_connect('localhost', '', ''); //Update hostname mysql_select_db("test", $con); //Update database name define ("MAX_SIZE","1000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if ( ($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif") && ($extension != "JPG") && ($extension != "JPEG") && ($extension != "PNG") && ($extension != "GIF") ) { echo '<h3>Unknown extension!</h3>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo '<h4>You have exceeded the size limit!</h4>'; $errors=1; } $image_name=time().'.'.$extension; $newname="images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h3>Copy unsuccessfull!</h3>'; $errors=1; } else echo '<h3>uploaded successfull!</h3>'; mysql_query("insert into list (image) values('".$newname."')"); } //Display image $rs=mysql_query("select * from list"); if($rs) while($row=mysql_fetch_array($rs)) { ?> <img width="150" src="<?php echo $row['image'];?>"><br> <?php } } ?>
任何想法?