PHP上传类,分享给大家,不足之处请见谅!
不足之处请高手见谅!
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->/*** 文件上传类 kangyangyang 2010-06-07* $loadfile 要上传的文件的文件域* $loadpath 文件存放路径* $loadhold 保留文件原名* $loadsize 文件大小限制 //默认是2048KB* $loadtype 文件类型限制 //默认支持 jpg|jpeg|gif|png|txt|rar|zip**/class uploadfile{private $loadfile;private $loadpath;private $loadsize;private $loadtype;private $loadhold = false;private $chkfile = true;private $file_name;private $extend_type;private $set_name;private $set_size;private $set_path;private $set_create_name;private $get_error;//构造函数function __construct($loadfile,$loadpath,$loadhold = false,$loadsize="2097152",$loadtype="jpg|jpeg|gif|png|txt|rar|zip"){ $this->loadfile = $loadfile; $this->loadpath = $loadpath; $this->loadsize = $loadsize; $this->loadtype = $loadtype; $this->loadhold = $loadhold; $this->filecheck();}//文件上传function filecheck(){ $filename = $_FILES[$this->loadfile]['name']; //文件名 $filetype = $_FILES[$this->loadfile]['type']; //文件类型 $filesize = $_FILES[$this->loadfile]['size']; //文件大小 $filepath = $_FILES[$this->loadfile]['tmp_name']; //临时文件 $fileerror= $_FILES[$this->loadfile]['error']; //错误代码 if($fileerror loadsize >= $filesize){ $this->set_size = $filesize; $ext = explode(".",$filename); $this->set_name = $ext; $ext_type = strtolower($ext[count($ext)-1]); $this->extend_type = $ext_type; $chk_type = explode("|",$this->loadtype); if(in_array($ext_type,$chk_type)){ $f_path = $this->get_folder(); $this->set_create_name = $createname = time().rand(1,9999); $this->file_name = $createname.".".$ext_type; if($this->loadhold){ $file_path = $f_path.$filename; $this->set_path = $file_path; }else{ $file_path = $f_path.$this->file_name; $this->set_path = $file_path; } $ckfile = move_uploaded_file($filepath,$file_path); if(!$ckfile){ $this->chefile = false; } }else{ $this->chkfile = false; } }else{ $this->chkfile = false; } }else{ $this->chkfile = false; $this->get_error = $fileerror; }}//生成的文件名function get_CreateName(){ if($this->CheckFile()){ if(!$this->loadhold){ return $this->set_create_name; } }}//返回文件夹路径function get_folder(){ if($this->CheckFile()){ if(!file_exists($this->loadpath)){ mkdir($this->loadpath,0777,true); chmod($this->loadpath,0777); } return $this->loadpath; }}//文件扩展名function get_type(){ if($this->CheckFile()){ return $this->extend_type; }}//文件名"不包括扩展名"function get_name(){ if($this->CheckFile()){ $filename = $this->set_name; unset($filename[count($filename)-1]); return implode(".",$filename); }}//返回文件大小function get_size(){ if($this->CheckFile()){ return $this->set_size; }}//返回文件全路径function get_path(){ if($this->CheckFile()){ return $this->set_path; }}//文件是否上传成功function CheckFile(){ return $this->chkfile;}//获取错误代码function get_error(){ if($this->CheckFile()){ return $this->get_error; }}}
------解决方案--------------------
不错,谢谢
------解决方案--------------------
------解决方案--------------------
不错,收藏
------解决方案--------------------
太牛了,收藏下

在PHP中修改数组元素的方法包括直接赋值和使用函数批量修改。1.对于索引数组,如$colors=['red','green','blue'],可以通过$colors[1]='yellow'修改第二个元素。2.对于关联数组,如$person=['name'=>'John','age'=>30],可以通过$person['age']=31修改age的值。3.使用array_map或array_walk函数可以批量修改数组元素,如$numbers=array_map(fun

在PHP中实现钩子函数可以通过观察者模式或事件驱动编程来实现。具体步骤如下:1.创建一个HookManager类,用于注册和触发钩子。2.使用registerHook方法注册钩子,并在需要时通过triggerHook方法触发钩子。钩子函数可以提高代码的可扩展性和灵活性,但需注意性能开销和调试复杂度。

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Atom编辑器mac版下载
最流行的的开源编辑器

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境