Home > Backend Development > PHP Tutorial > PHP A relatively complete simple file upload_PHP tutorial

PHP A relatively complete simple file upload_PHP tutorial

WBOY
Release: 2016-07-21 15:40:03
Original
945 people have browsed it

复制代码 代码如下:



文件上传


$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{
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 "不准上传次类型文件!";
}
}
?>






www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321442.htmlTechArticle复制代码 代码如下: HTML HEAD TITLE文件上传/TITLE meta http-equiv="Content-Type" content="text/html; charset=gb2312"/HEAD BODY ? $UploadedFile=$_FILES['UploadedFile']['t...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template