- 论坛徽章:
- 0
|
请各位帮看一下,我的代码哪里不对呀。
upload.php文件内容如下:
<html>
<head>
<title>文件上传表单</title>
</head>
<body>
<table>
<form enctype="multipart/form-data" name='myform' action='submit.php' method='post'>
<tr><td>选择上传文件</td><td>
<input name='myfile' type='file'></td></tr>
<tr><td>name:<input name='name' type='text'></td></tr>
<tr><td colspan='2'><input name='submit' value='上传'
type='submit'></td></tr>
</table>
</body>
</html>
submit.php的内容如下:
<?php
if($myfile != "none" && $myfile != "") { //有了上传文件了
//设置超时限制时间,缺省时间为 30秒,设置为0时为不限时
$time_limit=0;
set_time_limit($time_limit); //
//把文件内容读到字符串中
$fp=fopen($myfile, "rb");
if(!$fp) die("file open error");
$file_data = addslashes(fread($fp, filesize($myfile)));
fclose($fp);
unlink($myfile);
//文件格式,名字,大小
$file_type=$myfile_type;
$file_name=$myfile_name;
$file_size=$myfile_size;
//连接数据库,把文件存到数据库中
require ("../include/config.inc.php");
require ("./global.php");
$conn=mysql_pconnect($dbhost,$dbuser,$dbpasswd);
if(!$conn) die("error : mysql connect failed");
mysql_select_db("newscenter",$conn);
$sql="insert into receive
(file_data,file_type,file_name,file_size)
values ('$file_data','$file_type','$file_name',$file_size)";
$result=mysql_query($sql);
//下面这句取出了刚才的insert语句的id
$id=mysql_insert_id();
mysql_close($conn);
set_time_limit(30); //恢复缺省超时设置
echo "上传成功--- ";
echo "<a href='show_info.php?id=$id'>显示上传文件信息</a>";
}
else {
echo "你没有上传任何文件";
}
?>
另外,我将PHP.ini的配置也改了:
file_uploads = on ;
upload_max_filesize = 8m ;
post_max_size = 8m ;
并且也将IIS的脚本处理时间改到了10分钟,但还是出现不能上传超过600K的文件(上传时报找不到地址)。为什么?请各位帮帮忙,谢谢!
[ 本帖最后由 sangyu 于 2006-4-24 09:32 编辑 ] |
|