我做成了用户注册和留言板系统,就图片上传做不出,看了PHP手册,也不是很懂

解决方案 »

  1.   

    好的,代码贴出   upload_pic.htm<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>upload_pic.htm</title>
    <link href="51new.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <script language="JavaScript">
    //**********************************
    //判断输入是否合法的JavaScript小程序
    //**********************************
    function check()
    {
    if (window.document.pic.name.value =="")
    {
     alert(" 请输入图片名称.");
     document.pic.name.focus();
     return false;
    }
    return true;
     }
     </script>
    <table border="0" cellpadding="2" width="520" class="NT9">
          <?php
        //************************
        // 注意,在form标签中需要加入代码:
        // enctype="multipart/form-data",否则将
        //不能实现图片文件的上传.
        //***********************
        ?><form method="post" action="put_pic.php" name="pic" 
    enctype="multipart/form-data" onSubmit="return check();">
     <tr>
        <td width="520" bgcolor="#9FCF6F" colspan="2" >
      &nbsp;上传图片</td> 
      </tr>
      <tr>
        <td width="160" bgcolor="#c2e0a5" class="NT9" align="right">图片名称</td>
        <td width="360" class="NT9">
      <input type="text" name="name" size="35">
    </td>
      </tr>
      <tr>
        <td width="160" bgcolor="#C2E0A5" class="NT9" align="right">图片说明:</td>
        <td width="360" class="NT9">
    <textarea cols=34 rows=8 name=info></textarea>

    </td>
      </tr>
      <tr>
        <td width="160" bgcolor="#c2e0a5" class="NT9" align="right">图片文件</td>
        <td width="360" class="NT9">
    <input type="file" name="pic" size="25">
    </td>
      </tr>
      <tr>
        <td width="520" class="NT9W" align="center" colspan="2">
      <input type="submit" value="提交" name="submit">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" value="重写" name="B2">
        </td>
      </tr>
       </form>
    </table>
    </body>
    </html>   show.php
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>show</title>
    </head><body>
    <?php
    //连接服务器数据库
    Connid=@mysql_connect("localhost","weizhou45c5011","dellhappy2003");
    //************************
    //在数据表$table中读取字段id的值
    $sql="select pic from $_POST[photo] where id=$_POST[id]";
    $result=mysql_db_query("table",$sql);
    //读取图片文件内容
    $image=mysql_result($result,0,"pic");
    //显示图片文件
    echo $_POST[image];
    ?>
    </body>
    </html>    photo.php
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>photo</title><link href="51new.css" rel="stylesheet" type="text/css">
    </head><body>
    <table border="0" cellpadding="2" width="520" class="NT9" height="288">
      <tr>
      <td width="520" bgcolor="#9FCF6F" colspan="3" align="center" height="16">
             相片集</td>
      
      </tr>
    <?php
    //初始化分页变量$offset
    if($offset=="")
    {
    $offset=0;
    }
    //连接服务器数据库
    $Connid=@mysql_connect("localhost","weizhou45c5011","dellhappy2003");
    //在数据表photo中按字段id逆序
    //查询指定位置的6条记录的图片名称以及图片标识号等数据。
    $sql="select id,name from photo order by id desc limit $offset,6";
    $result=mysql_db_query("photo",$sql);$num=mysql_num_rows($result);
    if ($num !=0)
    {
    //初始化表格换行变量$i
    $i=0
    //以while循环的方式依次显示所查询到的图片文件的图片和名称
    while($r=mysql_fetch_array($result))
    {
      $id=$r["id"];
      $ftitle=$r["name"];
      if($i==0 or $i==3)
      
      {  
         echo "<tr>";
      }
      echo"<td width=165 bgcolor=#C2E0A5 class=NT9 align=center height=126>";
      //使用程序show.php来显示保存在数据表photo中的图片文件。
      echo"<a href=photo_info.php?id=$fid>";
      echo"<img border=0 src=";
      echo"show.php?table=photo&id=$fid";
      echo" height=60 ></a>";
      //显示图片文件的名称
      echo"<a href=photo_info.php?id=$fid>";
      echo"<p>$_POST[ftitle]</p></a></td>";
      
      if($i==2 or $i==5)
      {
         echo "<tr>";
       }
       $i++;
      }
     }
     ?>
     </table>
    </table>
    </body>
    </html>
      

  2.   

    忘记告诉大家,我的数据库可以把 “ 图片名称”和“图片说明”和“文件类型”  记录到MYSQL,其他的没记录,我的MYSQL列表也给大家吧,
    mysql>CREATE TABLE photo
         >(
         >id int(10) NOT NULL auto_increment,
         >filename varchar(30),
         >filesize int(20),
         >filetype varchar (10),
         >time datetime,
         >name varchar(50),
         >info text,
         >pic longblob,
         >PRIMARY KEY (id)
         >);
      

  3.   

    这是put_pic.php文件,但我到photo.php页面就空白的,没显示到图片,没到put_pic.php就这样了,不过还是贴出来看看<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>put_pic.</title>
    </head>
    <body>
    <?php
    //连接数据库
    $Connid=@mysql_Connect("localhost","weizhou45c5011","dellhappy2003");
    //将图片文件说明文字中的换行符转换为br符号
    $info=nl2br($info);
    //打开图片文件,将图片文件中的数据用函数addslashes处理,然后传递给变量$data,变量$data中所保存的数据就是图片文件的数据了。
    if($pic  !="none")
    {
     $fp=fopen($pic,"r");
     $data=addslashes(fread($fp,filesize($pic)));
     }
     //获取图片文件的大小
    $_POST[filesize]=filesize($pic);
     
     //获取图片文件的类型
    $_POST[filetype]=filetype($pic);
     
     //获取图片文件的文件名
    $_POST[filename]=basename($pic);
     
     //将服务器的时间传递给变量$date
    $date=date("Y-m-d H:i:s");
     
     $query="insert into photo
       (info,name,time,pic,filename,filesize,filetype)
       values
       ('$_POST[info]','$_POST[name]','$_POST[date]','$_POST[data]',
       '$_POST[filename]','$_POST[filesize]','$_POST[filetype]')";
       
       if (mysql_db_query("photo",$query))
       {
         header("Location: photo.php");
    }
    ?>
    </body>
    </html>
      

  4.   

    这是本什么“破”书,简直是在胡说八道!1、先不管你是否能正确的连接上mysql,你的用户名和口令也是eizhou45c5011,dellhappy2003吗?
    2、从show.php的$sql="select pic from $_POST[photo] where id=$_POST[id]";可以看出
    你的php版本>4.1.0。所以上传的图片要用$_FILES数组访问
    3、put_pic.php至少应为
    if(isset($_FILES['pic'])) {
     $fp=fopen($_FILES['pic']['tmp_name'],"r");
     $data=addslashes(fread($fp,$_FILES['pic']['size'])); //获取图片文件的大小
    $filesize = $_FILES['pic']['size'];
     
     //获取图片文件的类型
    $filetype = $_FILES['pic']['type'];
     
     //获取图片文件的文件名
    $filename = $_FILES['pic']['name'];
     
     //将服务器的时间传递给变量$date
    $date=date("Y-m-d H:i:s");
     
    $query="insert into photo
       (info,name,time,pic,filename,filesize,filetype)
       values
       ('$_POST[info]','$_POST[name]','$date','$data',
       '$filename','$filesize','$filetype')";
       
      

  5.   

    呵呵,我已经正确连接数据库了,提交后数据库“ 图片名称”和“图片说明”和“文件类型”已经记录到MYSQL,只有图片(pic),filename,filesize没记录.$_POST[]代码是我加的,不加就有版本问题。不过还是感谢