uploadfile.php:<?
if($upfile)
{
if($file1_size>3000000)
exit("上传文件的大小限制在3M内!");
if(copy($file1,"upload/$file1_name"))
echo "上传成功!";
else
echo "上传失败!";
}
else
{
?>
<html>
<head>
<title>文件上传</title>
</head>
<body>
<table>
<form enctype="multipart/form-data" action=<? echo $PHP_SELF; ?> method="post">
<tr>
<td>选择上传文件</td>
<td><input name="file1" type="file"></td>
</tr>
<tr>
<td colspan="2"><input name="upfile" value="上传" type="submit"></td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
if($upfile)
{
if($file1_size>3000000)
exit("上传文件的大小限制在3M内!");
if(copy($file1,"upload/$file1_name"))
echo "上传成功!";
else
echo "上传失败!";
}
else
{
?>
<html>
<head>
<title>文件上传</title>
</head>
<body>
<table>
<form enctype="multipart/form-data" action=<? echo $PHP_SELF; ?> method="post">
<tr>
<td>选择上传文件</td>
<td><input name="file1" type="file"></td>
</tr>
<tr>
<td colspan="2"><input name="upfile" value="上传" type="submit"></td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
解决方案 »
- 循环问题
- 来看看(中秋了)
- 求救啊,在线等
- 如何统计一个页面上的滞在时间,在线等,问题解决就揭帖,50分
- 我不给setcookie设定失效时间,为什么就不能跨二级域名了呢?
- 关于php用foreach获取复选框内容和javaScript冲突问题?
- PHP配置的一个错误问题?急,,,在线等。。。
- PHP 是否提供對 Sybase ASA 的支持 ?
- 问:搜索引擎的原理是什么?如何使网站容易被搜索?哪儿有这个的介绍?Thank you!
- 如何解决 curl: (35) Unknown SSL protocol error in connection to 错误?求大神
- 怎样让SQL SERVER 2000中的text域中的文本在PHP网页中自动换行?
- 关于 ssesion问题
如upload_max_filesize = 5M
(PHP 3>= 3.0.17, PHP 4 >= 4.0.3)is_uploaded_file -- Tells whether the file was uploaded via HTTP POST
Description
bool is_uploaded_file ( string filename)
Returns TRUE if the file named by filename was uploaded via HTTP POST. This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working--for instance, /etc/passwd. This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.
$_FILES['userfile']['name']
客户端机器文件的原名称。 $_FILES['userfile']['type']
文件的 MIME 类型,需要浏览器提供该信息的支持,例如“image/gif”。 $_FILES['userfile']['size']
已上传文件的大小,单位为字节。 $_FILES['userfile']['tmp_name']
文件被上传后在服务端储存的临时文件名。 $_FILES['userfile']['error']
用 filesize 超过上传限制就不执行上传动作!
$file_size=$file['size'];
得到字节数
再换算成k就行了
如果文件超出系统设置的最大值,可用下面的方法控制!
if($file1_size>1000000 || $file1_size==0)
exit("上传文件的大小限制在1M内!");