惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - 孤城浪子

[转].Net 中的许可证机制 [原]一步一步自己制作弹出框 [转]获取窗口 高 、宽 的JS代码 PHP连接mysql数据库 - 孤城浪子 - 博客园 动态调用Web Service - 孤城浪子 - 博客园 [转]ASP.NET 2.0 下加密解密算法的封装 [转]fckeidtor配置 [转]加解密技术 - 孤城浪子 - 博客园 [转]服务器推技术 [JavaScript]简单跟随鼠标移动的文字 排序算法 [仿照CloudGamer]写的颜色渐变 Asp.Net用SmtpClient发送邮件 项目中遇到的Vss和Sql问题 [JavaScript]拖动对象 - 孤城浪子 - 博客园 [JavaScript]飘浮文字 C#文件打散合并 C#调用Excel的宏 [网上整理]C#合并Excel
PHP文件上传
孤城浪子 · 2010-03-25 · via 博客园 - 孤城浪子

PHP中文件上传代码

   1.fileup.php 上传文件表单

代码

<html>
<head>
<title>文件上传</title>
</head>
<body>
<form enctype="multipart/form-data" action="up.php" method="POST">
    
<!-- MAX_FILE_SIZE must precede the file input field -->
    
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    
<!-- Name of input element determines name in $_FILES array -->
    Send this file: 
<input name="userfile" type="file" />
    
<input type="submit" value="Send File" />
</form>
</body>
</html>

2 文件上传接收代码

代码

<?php
function uploadfile($type,$name,$ext,$size,$error,$tmp_name,$targetname,$upload_dir)
{
    
$MAX_SIZE=2000000;
    
$FILE_MIMES=array('image/pjpeg','image/jpeg','image/jpg','image/gif','image/png');
    
$FILE_EXTS=array(".gif",".jpg",".png",".GIF",".JPG",".PNG");
    
$file_path=$upload_dir.$targetname;
    
if(!is_dir($upload_dir))
    {
        
if(!mkdir($upload_dir))
        
die("文件上传目录不存在并且无法创建文件上传目录");
        
if(!chmod($upload_dir,0755))
        
die("文件上传目录的权限无法设定为可读可写");
    }
    
if($size>$MAX_SIZE)
    
die("文件过大");
    
if($size==0)
    
die("请选择上传文件");
    
if(!in_array($type,$FILE_MIMES)||!in_array($ext,$FILE_EXTS))
    
die("文件类型错误");
    
if(!move_uploaded_file($tmp_name,$file_path))
    
die("复制文件失败");
    
switch($error)
    {
        
case 0:
            
return ;
        
case 1:
            
die("上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值");
        
case 2:
            
die("上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值");
        
case 3:
            
die("文件只有部分被上传");
        
case 4:
            
die("没有文件被上传");
    }

}

$name=$_FILES['userfile']['name'];
$arr=explode('.',$name);
$ext=".".$arr[count($arr)-1];
$reftime = localtime(time(), true);
                
$prftime = sprintf("%s-%s-%s-%s-%s-%s",
                                    
$reftime['tm_year']+1900,
                                    
$reftime['tm_mon']+1,
                                    
$reftime['tm_mday'],
                                    
$reftime['tm_hour'],
                                    
$reftime['tm_min'],
                                    
$reftime['tm_sec']
                                    );
$path=$_SERVER['DOCUMENT_ROOT']."/uploads/";
$tarName=$prftime.$ext;
$c=uploadfile($_FILES['userfile']['type'],$_FILES['userfile']['name'],$ext,$_FILES['userfile']['size'],$_FILES['userfile']['error'],$_FILES['userfile']['tmp_name'],$tarName,$path);
if($c==0)
{
    
echo "文件上传成功";
}
else
{
    
echo ("文件上传失败");
    
}
?>