PHP 一个比较完善的简单文件上传

前端之家收集整理的这篇文章主要介绍了PHP 一个比较完善的简单文件上传前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="30451" class="copybut" id="copybut30451" onclick="doCopy('code30451')"> 代码如下:

<div class="codebody" id="code30451">


<a href="/tag/wenjian/" target="_blank" class="keywords">文件</a><a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<?
$UploadedFile=$_FILES['UploadedFile']['tmp_name'];
$UploadedFile_name=$_FILES['UploadedFile']['name'];
$isTrue=false;
if($UploadedFile)
{
$store_dir=$_SERVER['DOCUMENT_ROOT'];
$accept_overwrite = 1;
$isTrue=true;
}
$fileName = date("YmtHis").$UploadedFile_name;
if (file_exists($store_dir . $fileName))
{
echo "存在相同文件名的文件";
}
$mytype =array(".jpg",".gif",".png");
$filetype=substr($_FILES['UploadedFile']['name'],strrpos($_FILES['UploadedFile']['name'],"."));
$typecount=0;
if($isTrue)
{
for($i=0;$i<count($mytype);$i++)
{
if($filetype==$mytype[$i])
{
$typecount++;
}
}
if($typecount>0)
{
if($_FILES['UploadedFile']['size']<1048576)
{
$b=move_uploaded_file($UploadedFile,$store_dir.$fileName);
if($b)
{
echo "
\n";
echo "原文件信息:
";
echo "名称:".$_FILES['UploadedFile']['name']."
\n";
echo "大小:".$_FILES['UploadedFile']['size']."
\n";
echo "类型:".$_FILES['UploadedFile']['type']."
\n";
echo "
\n";
echo "存入数据库名称为:".$fileName;
echo "
\n";
}
}
else
{
echo "文件大小不准超过1兆.";
}
}
else
{
echo "不准上传次类型文件!";
}
}
?>
<FORM ENCTYPE="multipart/form-data" ACTION="<?php echo $PHP_SELF ?>" METHOD="post">

<INPUT TYPE="submit" VALUE="上传文件">



猜你在找的PHP相关文章