看你的表,图片不是保存在mysql数据库中,数据库中只是保存了图片的路径。想保存的数据库中必须定义字段为longblob类型如:`image` longblob ,然后
<?$connect = MYSQL_CONNECT( "localhost", "root", "admin") or die("Unable to connect to MySQL server")
mysql_select_db("blogsystem") or die("Unable to select database")
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)))
$result=MYSQL_QUERY( "INSERT INTO ccs_image (description,bin_data,filename,filesize,filetype) VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')")
$id= mysql_insert_id()
print "<p>This file has the following Database ID: <a href='get_data.php?id=$id'><b>$id</b></a>"
MYSQL_CLOSE()
?>
//自己写限制<div class="daohang">
<div class="daohang_title">添加大三平面作品</div>
<li class="ti">
<div class="bd"><a href="../main_pingmian_1" target="mainFrame">大三作品</a></div>
<div class="bd"><a href="../main_pingmian_2" target="mainFrame">大二作品</a></div>
<div class="bd"><a href="../main_pingmian_3" target="mainFrame">大一作品</a></div>
</li>
</div><div class="daohang">
<form nname="form1" method="post" action="pm_cheak.php" onSubmit="return jiancha()" enctype="multipart/form-data"> //注意 enctype="multipart/form-data一定要有
<div class="daohang_title">请认真填写平面作品的资料</div> <div class="he" >
<li class="he_1">创作人</li>
<li class="he_2"><input name="pm_zuozhe" type="text" id="pm_zuozhe" value="" size="8" maxlength="4" /></li>
</div>
<div class="he" >
<li class="he_1"><span class="lanmu_title">作品说明</span></li>
<li class="he_2"><input name="pm_text" type="text" id="pm_text" value="" size="30" maxlength="30" /> 最多可以输入15个汉字或30个字母!</li>
</div>
<div class="he" >
<li class="he_1">连接地址</li>
<li class="he_2"><input name="pm_href" type="text" id="pm_href" value="" size="30" maxlength="30" />
如:www.hnanv0.com</li>
</div>
<div class="he" >
<li class="he_1">作品图片</li>
<li class="he_2">
<label>
<input type="file" name="pm_images" style="width:220border:1 solid #6899B7font-size:9ptsize="14" > </label> 允许上传文件类型为:jpg|jpeg|png|pjpeg|gif|bmp
</li>
</div>
<div class="he" >
<li class="he_1"></li>
<li class="he_2">
<label>
<input type="submit" name="upload" value="提交" />
</label>
<label>
<input type="reset" name="button2" id="button2" value="重置" >
</label>
<input name="date" type="hidden" id="date" value="">
</li>
</div>
</form></div>程序部分pm_cheak.php: <?
include ("../../../../conn.php")
if ($_POST['upload'] == '提交') { $pm_zuozhe = $_POST[pm_zuozhe]
$pm_text = $_POST[pm_text]
$pm_href = $_POST[pm_href]//一一对应 $pm_date = date("Y-m-d")$link=date("YmjHis") //获取当前时间
//为表单中提交的数据重新命名,以当前时间和随机数作为名称,其中使用$_FILES获取表单中真实的名称,使用strstr函数获取文件的后缀
$path=$link.mt_rand(1000,9999).strstr($_FILES["pm_images"]["name"],".")
$address="../../../../images/pm_btn/".$path //定义文件上传的路径
move_uploaded_file($_FILES["pm_images"]["tmp_name"],$address) //将文件上传到指定的文件中
$pm_images="images/pm_btn/".$path //获取上传文件在服务器中的存储路径
//将表单中提交的数据存储到数据库中 $sql = mysql_query("insert into pm(pm_zuozhe,pm_text,pm_href,pm_images,pm_date)values('$pm_zuozhe','$pm_text','$pm_href','$pm_images','$pm_date')")//执行插入语句
mysql_close($conn)//关闭连接
}
echo ("<script>alert('大三平面作品添加成功')window.location.href='add_pm_zuopin.php'</script>")
?>
<meta http-equiv="Content-Type" content="text/htmlcharset=GBK" />//注意编码格式
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)