0
  1. 一切正常,但出现此错误
    Notice: Undefined index: image in C:\wamp\www\neos-final\update-image.php on line 21
  2. 第 21 行是$image=$_FILES['image']['name'];
  3. 这条线怎么办:(

    <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 
            }
    }
    ?>
    

任何想法?

4

2 回答 2

1

Notice: Undefined index:当未定义数组变量的任何索引时,就会出现此通知。

isset在这里使用

if(isset($_FILES['image']))
{
    $image=$_FILES['image']['name'];
    //your rest of code here
}
于 2013-04-27T06:19:52.823 回答
0
Use php isset()

if(isset($_FILES['image']))
{
  // your code 
}
于 2013-04-27T06:21:35.960 回答