php 文件与文件目录批量删除
class deleteFile{
public $dir ='111cnnet/';
function deldir($this->dir)
{
if(is_dir($dir))
{
$rdir = $dir;
if($dirlist = scandir($rdir))
{
array_shift($dirlist);
array_shift($dirlist);
foreach($dirlist as $d){
$rd = $rdir.'/'.$d;
if(isset($d) && is_file($rd)){
unlink($rd);
}else{
$this->deldir($rd);
}
}
rmdir($rdir);
}else{
return false;
}
}
return true;
}
}
//使用方法
$delete = $this->deleteFile();
<div class=contentbox>
<div class="content_nav"><span class="tt">IP/域名WHOIS查询</span></div>
<div class=toolitem>
<br>
<form action="" method="get">
IP/域名:<input style="height:26px;border: 1px solid rgb(126, 157, 185); background-color: white;" id="query" maxlength="100" size="44" name="q" autocomplete="off" type="text" value="<?php教程 echo $q; ?>">
<span class="backgroundbord"><button class="srh_onesearch" type="submit">查 询</button></span>
</form>
</div>
</div>
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/ad/mid.php';
if($q2<>''){
if($isdomain){
echo '<div class=contentbox>';
echo '<div class="content_nav"><span class="tt">查询结果</span></div>';
echo '<div class=topmenuitem>';
// Server List File
$config['server_list'] = "./whois/servers.lst";
whois($domain);
echo '</div>';
echo '</div>';
}elseif($isip){
echo '<div class=contentbox>';
echo '<div class="content_nav"><span class="tt">查询结果</span></div>';
echo '<div class=topmenuitem>';
$sourcecode=getsourcecode("http://wq.apnic.net/apnic-bin/whois.pl?searchtext=".$q);
//echo $sourcecode;
preg_match('/(<pre><b><u>.*?)<div class="highlight" id="key">/s', $sourcecode, $ipwhois);
$result=$ipwhois[1];
$result=nl2br($result);
echo $result;
echo '</div>';
echo '</div>';
}else{
echo '<div class=contentbox>';
echo '<div class="content_nav"><span class="tt">Error!</span></div>';
echo '<div class=topmenuitem><p><font color=red>Error!</font>请确保你输入的不是域名(中文域名暂不支持)就是IP,你要是输入的是电话号码之类那我们真查不了!</p>';
echo '</div>';
echo '</div>';
}
}else{
echo '<div class=contentbox>';
echo '<div class="content_nav"><span class="tt">工具说明</span></div>';
echo '<div class=topmenuitem><p>请输入IP或域名,如chaxun.la或xxx.xxx.xxx.xxx</p>';
echo '</div>';
echo '</div>';
}
function whois() {
global $domain;
if(!$server = get_server()) {
die("无法查询此类型的域名");
}
$result = whois_request($server['server'], $domain);
if(!$result) {
echo "无法连接服务器";
die();
}
$server['info']=trim($server['info']);
if($server['info']){
$he = strpos($result,$server['info']) + strlen($server['info']);
$le = strpos($result, " ", $he);
$whois_server = trim(substr($result, $he, $le-$he));
$result2 = whois_request($whois_server, $domain);
if($result2){
echo nl2br($result." 以下信息来自:".$whois_server." ".$result2);
}else {
echo nl2br($result);
}
}else {
echo nl2br($result);
}
}
/*function whois() {
global $domain;
if(!$server = get_server()) {
echo "无法查询此类型的域名";
}else{
$result = whois_request($server['server'], $domain);
if(!$result) {
echo "无法连接服务器";
} else {
echo $result;
}
}
}
*/
function whois_request($server, $query)
{
$data = "";
if(!$fp = @fsockopen($server, 43)) {
Return false;
} else {
fputs($fp, $query . " ");
while (!feof($fp)) {
$data .= fread($fp, 1000);
}
fclose($fp);
}
//return nl2br($data);
return $data;
}
function get_server() {
global $config,$domain;
$serverarray = file($config['server_list']);
$i = 0;
foreach($serverarray as $key=>$val) {
if(substr($val,0,1) != "#") {
$server_p = explode("|",$val);
$server[$i]['tld'] = $server_p[0];
$server[$i]['server'] = $server_p[1];
$server[$i]['avail'] = $server_p[2];
$server[$i]['infoserver'] = $server_p[3];
$server[$i]['backserver'] = $server_p[4];
$server[$i]['info'] = $server_p[5];
}
$i++;
}
$domain_c = explode(".",$domain);
$partnum = count($domain_c);
$last_part_1 = $domain_c[$partnum-1];
$last_part_2 = $domain_c[$partnum-2];
foreach($server as $key=>$val) {
if($val['tld'] == $last_part_2.".".$last_part_1) {
Return $val;
} elseif($val['tld'] == $last_part_1) {
Return $val;
}
}
Return false;
}
$q=trim($_GET['q']);
$q2=$q;
if($q<>''){
if($q=matchip($q2)){
$isip=1;
}elseif($q=matchdomain($q2)){
$domain=topdomain($q2);
$isdomain=1;
}
}
<?php
$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 '<pre>';
var_dump($result);
echo '</pre>';
} else {
echo 'All OK';
}
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>advanced Upload Class - Demo</title>
</head>
<body>
<form action="auc.demo.php?action=uploadfile" method="post" enctype="multipart/form-data">
<input name="file[]" type="file" /><br />
<input name="file[]" type="file" /><br />
<input name="upload" type="submit" value="Upload File" />
</form>
</body>
</html>
<?php } ?>
类文件
<?php
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 '<pre>';
var_dump($files);
echo '</pre>';
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}";
}
}
?>
class Uploadimg{
private $_fileName=""; //文件域名称 如 'userfile'
private $_uploadDir = ''; //上传路径 如 ./upload/
/*上传参数配置*/
private $_config = array(
'type'=>array('image/jpeg','image/jpg',
'image/pjpeg','image/gif'), //上传的类型
'size'=>1, //文件最大容量单位是M
'width'=>1000, //图片的最大宽度
'height'=>800 //图片的最大高度
);
/**
* 构造函数
*
* @param string $fileName
* @param string $uploadDir
* @param array $config
*/
function __construct($fileName,$uploadDir,$config='')
{
$this->_fileName = $fileName;
$this->_uploadDir = $uploadDir;
if($config == "" or empty($config) or !is_array($config)){
$this->_config = $this->_config;
}else{
$this->_config = $config;
}
}
/**
* 检测容量是否超过
*
* @return boolean
*/
function checkSize()
{
if($_FILES[$this->_fileName]['size'] > $this->_config['size']*1024*1024){
return false;
}else{
return true;
}
}
/**
* 获取图片信息
*
* @return boolean
*/
function getInfo()
{
return @getimagesize($_FILES[$this->_fileName]['tmp_name']);
}
/**
* 检测后缀名
*
* @return boolean
*/
function checkExt()
{
$imageInfo = $this->getInfo();
if(in_array($imageInfo['mime'],$this->_config['type'])){
return true;
}else{
return false;
}
}
/**
* 获取后缀名
*
* @return boolean
*/
function getExt()
{
$imageInfo = $this->getInfo();
switch($imageInfo['mime']){
case 'image/jpeg':$filenameExt = '.jpg';break;
case 'image/jpg':$filenameExt = '.jpg';break;
case 'image/pjpeg':$filenameExt = '.jpg';break;
case 'image/gif':$filenameExt = '.gif';break;
default:break;
}
return $filenameExt;
}
/**
* 检测尺寸
*
* @return boolean
*/
function checkWh()
{
$imageInfo = $this->getInfo();
if(($imageInfo[0] > $this->_config['width']) or ($imageInfo[1] > $this->_config['height'])){
return false;
}else{
return true;
}
}
/**
* 上传一张图片
*
* @return string or int
*/
function uploadSingleImage()
{
if($this->checkSize() == false){
return (-3); /*上传容量过大*/
exit();
}
if($this->checkExt() == true){
$filenameExt = $this->getExt();
}else{
return (-2); /*上传格式错误*/
exit();
}
if($this->checkWh() == false){
return (-1); /*上传图片太宽或太高*/
exit();
}
$file_new_name = date('YmdHis').$filenameExt;
$file_new_name_upload = rtrim($_SERVER['DOCUMENT_ROOT'],'/').$this->_uploadDir.$file_new_name;
if(@move_uploaded_file($_FILES[$this->_fileName]['tmp_name'],$file_new_name_upload)){
return $file_new_name;
}else{
return (0); /*上传失败*/
}
}
/**
* 删除图片
*
* @param string $imageName
* @return boolen
*/
function delImage($imageName)
{
$path = rtrim($_SERVER['DOCUMENT_ROOT'],'/').$this->_uploadDir.$imageName;
if(unlink($path) == true){
return true;
}else{
return false;
}
}
}
class Trees{
private $_keyId = 'Id';
private $_keyName = 'Name';
private $_keyFid = 'Fid';
function __construct($keyId='',$keyName='',$keyFid='')
{
if($keyId==""){$this->_keyId = $this->_keyId;}else{$this->_keyId = $keyId;}
if($keyName==""){$this->_keyName = $this->_keyName;}else{$this->_keyName = $keyName;}
if($keyFid==""){$this->_keyFid = $this->_keyFid;}else{$this->_keyFid = $keyFid;}
}
public function treeListAll($fid,$step=0,&$fromArray,&$resultArray)
{
$step++;
foreach ($fromArray as $k=>$v){
if($v[$this->_keyFid] == $fid){
$newArray[] = $v;
}
}
if(isset($newArray)){
foreach ($newArray as $k=>$v){
$this->treeListAll($v[$this->_keyId],$step,$fromArray,$resultArray);
$v['Step'] = $step;
$resultArray[] = $v;
}
}
}
public function getTreeListAll($fid=0,$step=0,&$fromArray,&$resultArray)
{
$step++;
foreach ($fromArray as $k=>$v){
if($v[$this->_keyFid] == $fid){
$newArray[] = $v;
}
}
if(isset($newArray)){
foreach ($newArray as $k=>$v){
$this->getTreeListAll($v[$this->_keyId],$step,$fromArray,$resultArray);
$v['Step'] = $step;
$resultArray[] = $v;
}
}
}
public function getTreeList($id = 0,&$fromArray)
{
$resultArray = array();
$this->getTreeListAll($id,0,$fromArray,$resultArray);
$resultArray = array_reverse($resultArray);
return $resultArray;
}
public function getTreeArray($id = 0,&$fromArray)
{
$result_one_array = $this->getTreeList($id,$fromArray);
foreach ($result_one_array as $k=>$v){
$result_two_array[] = array($v[$this->_keyId]);
}
if(isset($result_two_array)){
for ($i=0;$i<count($result_two_array);$i++){
for ($j=0;$j<count($result_two_array[$i]);$j++){
$result[] = $result_two_array[$i][$j];
}
}
}else{
$result = array();
}
return $result;
}
public function treeListAllTop($fid,$step=0,&$fromArray,&$resultArray)
{
$step++;
foreach ($fromArray as $k=>$v){
if($v[$this->_keyId] == $fid){
$newArray[] = $v;
}
}
if(isset($newArray)){
foreach ($newArray as $k=>$v){
$this->treeListAllTop($v[$this->_keyFid],$step,$fromArray,$resultArray);
$v['Step'] = $step;
$resultArray[] = $v;
}
}
}
public function getTreeListAllTop($fid=0,$step=0,&$fromArray,&$resultArray)
{
$step++;
foreach ($fromArray as $k=>$v){
if($v[$this->_keyId] == $fid){
$newArray[] = $v;
}
}
if(isset($newArray)){
foreach ($newArray as $k=>$v){
$this->getTreeListAllTop($v[$this->_keyFid],$step,$fromArray,$resultArray);
$v['Step'] = $step;
$resultArray[] = $v;
}
}
}
public function getTreeListTop($id = 0,&$fromArray)
{
$resultArray = array();
$this->getTreeListAllTop($id,0,$fromArray,$resultArray);
$resultArray = array_reverse($resultArray);
return $resultArray;
}
public function getTreeArrayTop($id = 0,&$fromArray)
{
$result_one_array = $this->getTreeListTop($id,$fromArray);
foreach ($result_one_array as $k=>$v){
$result_two_array[] = array($v[$this->_keyFid]);
}
if(isset($result_two_array)){
for ($i=0;$i<count($result_two_array);$i++){
for ($j=0;$j<count($result_two_array[$i]);$j++){
$result[] = $result_two_array[$i][$j];
}
}
}else{
$result = array();
}
return $result;
}
public function makeOptionString($sourcArray,$firstHint="顶级分类",$selectId=array('-1'),$type=0)
{
if($type==0){
if($firstHint != ""){
$str = '<option value="0">'.$firstHint.'</option>';
}else{
$str = '';
}
foreach ($sourcArray as $value){
$level="";
for($i=1;$i<$value['Step'];$i++){
$level =$level."----|";
}
$selectStr = "";
if(in_array($value[$this->_keyId],$selectId)){
$selectStr = "selected";
}else{
}
$str.='<option value="'.$value[$this->_keyId].'" '.$selectStr.'>|'.$level.$value[$this->_keyName]."</option>";
$level="";
}
}else{
$flagStep =-1;
$str = '<option value="0">'.$firstHint.'</option>';
foreach ($sourcArray as $value){
$level="";
for($i=1;$i<$value['Step'];$i++){
$level =$level."----|";
}
$selectStr = "";
if($type==$value[$this->_keyId]){
$flagStep = $value['Step'];
}else{
if($flagStep != -1 && $value['Step']>$flagStep){
}else{
if($flagStep != -1 && $value['Step']<=$flagStep){
$flagStep = -1;
}
if($value[$this->_keyId] == $selectId){
$selectStr = "selected";
}
$str.='<option value="'.$value[$this->_keyId].'" '.$selectStr.'>|'.$level.$value[$this->_keyName]."</option>";
}
}
$level="";
}
}
return $str;
}
}
相关文章
- 下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
Jupyter Notebook读取csv文件出现的问题及解决
这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06- 有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
- C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
- 这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
- 这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
- 复制代码 代码如下: <td> <a href="/member/life/edit_ppt/<?php echo $v->id;?>" class="btn">编辑</a> <a href="javascript:;" onclick="if(confirm('您确定删除这条记录?')){location.href='/member/life/d...2014-06-07
php无刷新利用iframe实现页面无刷新上传文件(1/2)
利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25- 要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
- 又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
- 今天小编在这里就来给photoshop的这一款软件的使用者们来说下AI源文件转photoshop图像变模糊问题的解决教程,各位想知道具体解决方法的使用者们,那么下面就快来跟着小编...2016-09-14
- 这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
- 步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
- 这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
- 这篇文章主要介绍了C#使用StreamWriter写入文件的方法,涉及C#中StreamWriter类操作文件的相关技巧,需要的朋友可以参考下...2020-06-25
ant design中upload组件上传大文件,显示进度条进度的实例
这篇文章主要介绍了ant design中upload组件上传大文件,显示进度条进度的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-29- 举一个案例:复制代码 代码如下:<?phpclass Downfile { function downserver($file_name){$file_path = "./img/".$file_name;//转码,文件名转为gb2312解决中文乱码$file_name = iconv("utf-8","gb2312",$file_name...2014-06-07
- 最近由于项目的需要,需要动态的添加和删除table中的tr,感觉用JS可以实现,但是在网上找了一下,单纯的自己写JS,感觉太麻烦,而且也不好维护。于是想到了最近学的jQuery。这篇文章给大家用实例介绍了jQuery动态添加与删除tr行的方法,有需要的朋友们可以参考借鉴。...2016-10-20