热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

php高级完美多文件上传类程序-PHP源码

ec(2);<?php$action$_GET[action];require_once(auc.main.class.inc.php);$aucnewauc();if($actionuploadfile){ $aucnewauc();  $result$auc->upload(&

$action = $_GET['action'];
require_once('auc.main.class.inc.php');

$auc = new auc();

if ($action == 'uploadfile') {
$auc = new auc();

$result = $auc->upload("file");
if (is_array($result)) {
echo 'Something Went Wrong';
echo '

';
var_dump($result);
echo '
';
} else {
echo 'All OK';
}
} else {
?>
















类文件

class auc {
public $errors = array(); //array used to store any errors that occur.
public $upload_dir = ''; //the upload_dir being used by the script
public $make_safe = false; //default don't modify the file name to safe version
public $max_file_size = 1048576; //Max File Size in Bytes, 1MB
public $overwrite = false; //default don't overwrite files that already exsist
public $check_file_type = false; //don't check for file type by default but can check for allowed and denied files.
public $allowed_mime_types = array('image/jpeg', 'image/png', 'image/gif', 'image/tiff'); //array of allowed mime types used when check_file_type is set to allowed
public $denied_mime_types = array('application/x-php', 'text/html'); //array of denied mime types used when check_file_type is set to denied

/**
* Check if the upload dir is valid, if it is not valid attempt to make the dir, if dir is succesfully created chmod it to 0777.
* If any elments fail return false else set upload_dir and return true.
* @param string $dir
* @param boolean $mkdir
* @return true or false
*/
public function upload_dir($dir, $mkdir = false) {
$errors =& $this->errors;
$status = true;

if (!is_dir($dir)) {
if ($mkdir) {
if (!mkdir($dir)) {
$status = false;
} else {
if (!chmod($dir, 0777)) $status = false;
}
} else {
$status = false;
}
}

if ($status) {
$this->upload_dir = $dir;
return true;
} else {
$errors['general'][] = 'Upload Dir is Not Valid and/or a dir could not be created/chmod.';
return false;
}
}

/**
* check that the upload dir is valid and that it is writeable
*
* @param string $dir
* @return true or false
*/
public function check_dir($dir) {
if (!is_dir($dir) || !is_writable($dir)) return false;

return true;
}

/**
* make the uploaded file name safe
*
* @param string $file_name
* @return safe file name
*/
public function make_safe($file_name) {
return str_replace(' ', '_', $file_name);
}

/**
* Check the Attemted Uploads for errors etc if everything goes good move the file, to the upload_dir.
*
* @param array $object
* @return unknown
*/
public function upload($object) {
$errors =& $this->errors;

if (empty($errors['general'])) {
if (empty($this->upload_dir)) $this->upload_dir = dirname(__FILE__).'/'; //if no default upload_dir has been specified used the current dir.

if ($this->check_dir($this->upload_dir)) {
$files = $_FILES[$object];
$count = count($files['name']) - 1;

echo '

';
var_dump($files);
echo '
';

for ($current = 0; $current <= $count; $current++) {
$error = '';
try {
//check for $_FILES Errors
switch ($files['error'][$current]) {
case 0 : break;
case 1 : $error = $files['name'][$current].' exceeds the upload_max_filesize directive in php.ini'; break;
case 2 : $error = $files['name'][$current].' exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; break;
case 3 : $error = $files['name'][$current].' was only partially uploaded'; break;
case 4 : $error = 'No file was uploaded'; break;
case 6 : $error = 'Missing a temporary folder'; break;
case 7 : $error = 'Failed to write '.$files['name'][$current].' to disk'; break;
case 8 : $error = $files['name'][$current].' stopped by extension'; break;
default : $error = 'Unidentified Error, caused by '.$files['name'][$current]; break;
}
if ($error)
throw new TrigerErrorException($error, $files['name'][$current]);

//check that the file is not empty
if ($files['size'][$current] <= 0)
throw new TrigerErrorException($files['name'][$current].' is empty', $files['name'][$current]);

//check that the file does not exceed the defined max_file_size
if ($this->max_file_size) {
if ($files['size'][$current] >= $this->max_file_size)
throw new TrigerErrorException($files['name'][$current].' exceeds defined max_file_size', $files['name'][$current]);
}

if ($this->check_file_type == 'allowed' && !in_array($files['type'][$current], $this->allowed_mime_types)) {
throw new TrigerErrorException($files['name'][$current].' is not an allowed type', $files['name'][$current]);
} elseif ($this->check_file_type == 'denied' && in_array($files['type'][$current], $this->denied_mime_types)) {
throw new TrigerErrorException($files['name'][$current].' is a denied type', $files['name'][$current]);
}

//if make_safe is true call make safe function
if ($this->make_safe)
$files['name'][$current] = $this->make_safe($files['name'][$current]);

//if overwrite is false and the file exists error
if (!$this->overwrite && file_exists($this->upload_dir.$files['name'][$current]))
throw new TrigerErrorException($files['name'][$current].' already exsists', $files['name'][$current]);

//move the uploaded file, error if anything goes wrong.
if (!move_uploaded_file($files['tmp_name'][$current], $this->upload_dir.$files['name'][$current]))
throw new TrigerErrorException($files['name'][$current].' could not be moved', $files['name'][$current]);
} catch (TrigerErrorException $e) {
$errors[$files['name'][$current]][] = $e->Message();
}
}

if (empty($errors)) {
//return true if there where no errors
return true;
} else {
//return the errors array if there where any errros
return $errors;
}
} else {
//return false as dir is not valid
$errors['general'][] = "The Specified Dir is Not Valid or is Not Writeable";
return false;
}
}
}
}

/**
* Handle the Exceptions trigered by errors within upload code.
*
*/
class TrigerErrorException extends Exception {
protected $file = "";
public function __construct($message, $file = "", $code = 0) {
$this->file = $file;
parent::__construct($message, $code);
}

public function Message() {
return "{$this->message}";
}
}
?>


推荐阅读
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 2018年人工智能大数据的爆发,学Java还是Python?
    本文介绍了2018年人工智能大数据的爆发以及学习Java和Python的相关知识。在人工智能和大数据时代,Java和Python这两门编程语言都很优秀且火爆。选择学习哪门语言要根据个人兴趣爱好来决定。Python是一门拥有简洁语法的高级编程语言,容易上手。其特色之一是强制使用空白符作为语句缩进,使得新手可以快速上手。目前,Python在人工智能领域有着广泛的应用。如果对Java、Python或大数据感兴趣,欢迎加入qq群458345782。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • Monkey《大话移动——Android与iOS应用测试指南》的预购信息发布啦!
    Monkey《大话移动——Android与iOS应用测试指南》的预购信息已经发布,可以在京东和当当网进行预购。感谢几位大牛给出的书评,并呼吁大家的支持。明天京东的链接也将发布。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
author-avatar
萝莉控的许123321
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有