php简单实用文件上传代码
<?php
if($_files['file']){
// -----------------------------------------------------------------------//
//
// 说明:文件上传 日期:2004-5-2
//
// -----------------------------------------------------------------------//
//php简单实用文件上传代码
// 上传设置
$maxsize=10002400; //最大允许上传的文件大小
$alltype=array(".php",".php3"); //所有允许上传的文件类型
$imgtype=array(".php",".php3"); //类型
// 判断文件大小
if($_files['file']['size']>$maxsize) {
echo "您上传的资料大于10000k";
exit;
}
// 判断文件类型
$type=strstr($_files['file']['name'],".");
if(in_array($type,$alltype)){
echo "不允许上传该类型的文件";
exit;
}
include './uploaddir.php';
$time=date("ymd-his",time());
$fn=$time.$type;
$destination=$updir."/".$fn;
if(@move_uploaded_file($_files['file']['tmp_name'], $destination)){
@chmod($destination, 0777);
$fileurl=$updir."/".$destination;
$fileurl="".$destination;
}else{
echo "上传失败!";
echo "<script>location.href=history.back()</script>";
}
// ----------------------------------------------------------------------------------------------//
}
if($back=="no"):
echo "ok";
exit;
endif;
?><html>
<head>
<title>上传文件</title>
<script language="javascript">
function isnull()
{
if(document.all.fileurl.value!="")insert();
}
function insert()
{
images='<a href="'+insertpic.fileurl.value+'">附带文件,请点击下载</a>';
edit = window.opener.document.lfj_iframe.document.selection.createrange();
edit.pastehtml (images);
window.close();
}
</script>
<style>
body { font-size: 12px; font-family: tahoma,宋体;}
table { empty-cells: show;}
td { font-size: 12px; color: #000000; font-family: tahoma,宋体;margin: 5}
</style>
</head>
<body leftmargin=12 topmargin=12 marginwidth=2 marginheight=2 bgcolor='#d6d3ce' style="border:0px" onload=isnull()>
<form action=<?=$php_self?> name=insertpic enctype=multipart/form-data method=post>
<table>
<tr>
<td></td>
<td width=60>上传文件</td>
<td><input class=mmcinb type="file" name="file" size="14">
<input class=mmcinb type="submit" value="上传"></td>
</tr>
<tr>
<td></td>
<td>文件url</td>
<td><input class=mmcinb type="text" name="fileurl" value="<?=$fileurl?>" size="26">
<button onclick=insert()>插入</button></td>
</tr>
<tr>
<td></td>
<td colspan=2 align=left><font color=red>可以直接输入文件的url,点击插入即可(不能有中文)<br>
</font></td>
</tr>
</table>
</form>
<script language="javascript">
<!--
//picurl.focus();
//-->
</script>
</body>
</html>教程网址:http://www.phprm.com/code/33637.html
欢迎收藏∩_∩但请保留本文链接。