PHP文件创建、复制、移动、删除文件

 更新时间:2016年11月25日 15:53  点击:1435
 代码如下 复制代码
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>创建、复制、移动、删除文件</title>
<style type="text/css教程">
<!--
body {
margin-left: 00px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style></head>
<body>
<table width="350" border="1" cellpadding="0" cellspacing="0">
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326ssss.gif">
<form name="form1" method="post" action="index.php教程">
<tr>
<td width="95" height="39"> </td>
<td width="171" rowspan="2" align="left" valign="middle"> <input name="fopens" type="text" id="copy2" size="22"></td>
<td width="84" rowspan="2" valign="middle"><input name="submit4" type="submit" id="submit4" value="提交"></td>
</tr>
<tr>
<td height="41"> </td>
</tr>
</form>
</table></td>
</tr>
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326s.gif">
<form name="form1" method="post" action="index.php">
<tr>
<td width="111" height="39"> </td>
<td width="155" valign="bottom"><input name="copys" type="text" id="copys2" size="20">
</td>
<td width="84" rowspan="2" valign="middle"><input type="submit" name="submit" value="提交"></td>
</tr>
<tr>
<td height="41"> </td>
<td valign="top"><input name="copy2" type="text" id="copy22" size="20"></td>
</tr>
</form>
</table></td>
</tr>
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326ss.gif">
<form name="form1" method="post" action="index.php">
<tr>
<td width="111" height="39"> </td>
<td width="115" valign="bottom"><input name="moves" type="text" id="moves3" size="20">
</td>
<td width="84" rowspan="2"><input type="submit" name="submit2" value="提交"></td>
</tr>
<tr>
<td height="41"> </td>
<td valign="top"><input name="moves2" type="text" id="moves22" size="20"></td>
</tr>
</form>
</table></td>
</tr>
<tr>
<td><table width="350" height="80" border="0" cellpadding="0" cellspacing="0" background="images/326sss.gif">
<form name="form1" method="post" action="index.php">
<tr>
<td width="104"> </td>
<td width="236"><input name="delete" type="text" id="delete2">
<input type="submit" name="submit3" value="提交"></td>
</tr>
</form>
</table></td>
</tr>
</table>
</body>
</html>

php代码

 代码如下 复制代码

<?php session_start();
if($submit=="提交"){
$copy=$_post[copys];
$copys2=$_post[copy2];
if(copy($copy,$copys2)==true){echo "复制成功!!";}else{echo "失败!!";};
}
if($submit2=="提交"){
$moves=$_post[moves];
$moves2=$_post[moves2];
if(rename($moves,$moves2)==true){echo "移动成功!!";}else{echo "失败!!";};
}

if($submit3=="提交"){
$delete=$_post[delete];
if(unlink($delete)==true){echo "删除成功!!";}else{echo "失败!!";};
}
if($submit4=="提交"){
$fopens=$_post[fopens];
if(fopen($fopens,"w")==true){echo "创建成功!!";}else{echo "失败!!";};
}

?>

function whois_hichina($domain) {
preg_match("|<pre>(.+?)</pre>|is", @file_get_contents('http://whois.hichina.com/cgi-bin/whois?domain='.$domain.''), $whois);

$whois[0] = str_replace('友情提示:按注册局要求,过期域名可能会处于注册商自动续费期阶段,您在此查询所看到的域名到期日仅供参考<br />请您<a href="http://www.net.cn/has_client/userlogon/user_logon1.asp教程" target="_blank" class="link_gl">进入会员区</a>查看该域名的实际到期时间,并请及时进行续费,谢谢!', '', ($whois[0]));//过滤掉此段文字


return $whois[0]);

}

//新网 whois (非新网提供,只是根据新网自身网站的url修改实现)
function whois_xinnet($domain) {
preg_match("|<div class="lytableinfowrap">(.+?)</div>|is", @file_get_contents('http://www.xinnet.cn/modules/agent/serv/pages/domain_whois.jsp教程?domainnamewhois='.$domain.'&nocode=nocode'), $whois);

return $whois[0];
}
}

一、编码范围
1. gbk (gb2312/gb18030)
x00-xff gbk双字节编码范围
x20-x7f ascii
xa1-xff 中文
x80-xff 中文

2. utf-8 (unicode)
u4e00-u9fa5 (中文)
x3130-x318f (韩文)
xac00-xd7a3 (韩文)
u0800-u4e00 (日文)
ps教程: 韩文是大于[u9fa5]的字符

正则例子:
preg_replace("/([x80-xff])/","",$str);
preg_replace("/([u4e00-u9fa5])/","",$str);

二、代码例子

//判断内容里有没有中文-gbk (php教程)
function check_is_chinese($s){
    return preg_match('/[x80-xff]./', $s);
}
//获取字符串长度-gbk (php)
function gb_strlen($str){
    $count = 0;
    for($i=0; $i<strlen($str); $i++){
        $s = substr($str, $i, 1);
        if (preg_match("/[x80-xff]/", $s)) ++$i;
        ++$count;
    }
    return $count;
}
//截取字符串字串-gbk (php)
function gb_substr($str, $len){
    $count = 0;
    for($i=0; $i<strlen($str); $i++){
        if($count == $len) break;
        if(preg_match("/[x80-xff]/", substr($str, $i, 1))) ++$i;
        ++$count;      
    }
    return substr($str, 0, $i);
}
//统计字符串长度-utf8 (php)
function utf8_strlen($str) {
    $count = 0;
    for($i = 0; $i < strlen($str); $i++){
        $value = ord($str[$i]);
        if($value > 127) {
            $count++;
            if($value >= 192 && $value <= 223) $i++;
            elseif($value >= 224 && $value <= 239) $i = $i + 2;
            elseif($value >= 240 && $value <= 247) $i = $i + 3;
            else die('not a utf-8 compatible string');
        }
        $count++;
    }
    return $count;
}

//截取字符串-utf8(php)
function utf8_substr($str,$position,$length){
    $start_position = strlen($str);
    $start_byte = 0;
    $end_position = strlen($str);
    $count = 0;
    for($i = 0; $i < strlen($str); $i++){
        if($count >= $position && $start_position > $i){
            $start_position = $i;
            $start_byte = $count;
        }
        if(($count-$start_byte)>=$length) {
            $end_position = $i;
            break;
        }  
        $value = ord($str[$i]);
        if($value > 127){
            $count++;
            if($value >= 192 && $value <= 223) $i++;
            elseif($value >= 224 && $value <= 239) $i = $i + 2;
            elseif($value >= 240 && $value <= 247) $i = $i + 3;
            else die('not a utf-8 compatible string');
        }
        $count++;
    }
    return(substr($str,$start_position,$end_position-$start_position));
}

//字符串长度统计-utf8 [中文3个字节,俄文、韩文占2个字节,字母占1个字节] (ruby)
def utf8_string_length(str)
    temp = cgi::unescape(str)
    i = 0;
    j = 0;
    temp.length.times{|t|
        if temp[t] < 127
            i += 1
        elseif temp[t] >= 127 and temp[t] < 224
            j += 1
            if 0 == (j % 2)
                i += 2
                j = 0
            end
        else
            j += 1
            if 0 == (j % 3)
                i +=2
                j = 0
            end
        end
    }
    return i
}

//判断是否是含有韩文-utf-8 (网页特效)
function checkkoreachar(str) {
    for(i=0; i<str.length; i++) {
        if(((str.charcodeat(i) > 0x3130 && str.charcodeat(i) < 0x318f) || (str.charcodeat(i) >= 0xac00 && str.charcodeat(i) <= 0xd7a3))) {
            return true;
        }
    }
    return false;
}

//判断是否有中文字符-gbk (javascript)
function check_chinese_char(s){
    return (s.length != s.replace(/[^x00-xff]/g,"**").length);
}

文章列出一三种删除数组中重复元素函数与实例代码,前二种是利用循环来判断删除重复的数组值,最后一种是比经典的,利用了array_flip()的特性,把值变成键名,再返回重复键名就会丢失。

function delsame(&$array)
{
$i = 0;
while(isset($array[$i]))
{
$j = $i + 1;
while(isset($array[$j]))
{
if($array[$i] == $array[$j]) //如果发现后面有重复的元素
{
delmember($array, $j); //把它删除
$j--; //重新检查补上来的元素是否是重复的
}
$j ++;
}
$i ++;
}
}

//删除数组中重复元素的函数

 代码如下 复制代码
function delmember(&$array, $id)
{
$size = count($array);
for($i = 0; $i <$size - $id - 1; $i ++)
{
$array[$id + $i] = $array[$id + $i + 1];
}
unset($array[$size - 1]);
}

//使用例子:

 代码如下 复制代码
$output = array(1, 2, 2, 'www.111cn.net', 5, 4, 4, 4, 2, 7, 5, 9, 10);
delsame($output);
while(list($key, $value) = each($output))
{
echo "$key:$value"."<br>";
}


//方法二

 代码如下 复制代码

function uniquearray($array)

{

// get unique elts as keys in assoc. array

for ($i=0,$n=count($array, 1);$i<$n;$i )

$u_array[$array[$i]] = 1;

 

// copy keys only into another array

reset($u_array, 1);

for ($i=0,$n=count($u_array, 1);$i<$n;$i ) {

$unduplicated_array[] = key($u_array, 1);

next($u_array, 1);

}

return $unduplicated_array;

}

//方法三

 代码如下 复制代码

$hills=array("first"=>"data1","second"=>"www.111cn.net","third"=>"data1");
$hills=array_flip($hills); //还原键名
$hills1=array_flip(array_flip($hills));//删除重复
print_r( $hills1  );

/*
array array_flip ( array trans )
  array_flip() 返回一个反转后的 array,例如 trans 中的键名变成了值,而 trans 中的值成了键名。
  注意 trans 中的值需要能够作为合法的键名,例如需要是 integer 或者 string。如果值的类型不对将发出一个警告,并且有问题的键/值对将不会反转。
  如果同一个值出现了多次,则最后一个键名将作为它的值,所有其它的都丢失了。
  array_flip() 如果失败返回 false。

*/

本款函数是一款利用递归来一步步删除目录下文件与当前目录所有子目录哦,不管目录为不为空都可以删除,

<?php教程
set_time_limit(0);
$filenum=0;
function deldir($dir){
 global $filenum;
 $dh=opendir($dir);
 while ($file=readdir($dh)){
  if($file!="."&&$file!=".."){
   $fullpath=$dir."/".$file;
    if(!is_dir($fullpath)){
     unlink($fullpath);
    if(($filenum %100)==0){
     echo "*";
    }
    $filenum=$filenum+1;
   }else{
    deldir($fullpath);
   }
  }
 }
 closedir($dh);
}
deldir("/www.111cn.net/");
echo "delete cache file success. total:".$filenum;
?>

[!--infotagslink--]

相关文章

  • php读取zip文件(删除文件,提取文件,增加文件)实例

    下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
  • Jupyter Notebook读取csv文件出现的问题及解决

    这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06
  • Photoshop打开PSD文件空白怎么解决

    有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
  • 解决python 使用openpyxl读写大文件的坑

    这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
  • C#实现HTTP下载文件的方法

    这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • SpringBoot实现excel文件生成和下载

    这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
  • C#操作本地文件及保存文件到数据库的基本方法总结

    C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
  • 删除条目时弹出的确认对话框

    复制代码 代码如下: <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
  • MySQL快速复制数据库数据表的方法

    某些时候,例如为了搭建一个测试环境,或者克隆一个网站,需要复制一个已存在的mysql数据库。使用以下方法,可以非常简单地实现。假设已经存在的数据库名字叫db1,想要复制一份,命名为newdb。步骤如下:1. 首先创建新的数据库newd...2015-10-21
  • php无刷新利用iframe实现页面无刷新上传文件(1/2)

    利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25
  • php批量替换内容或指定目录下所有文件内容

    要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
  • PHP文件上传一些小收获

    又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
  • AI源文件转photoshop图像变模糊问题解决教程

    今天小编在这里就来给photoshop的这一款软件的使用者们来说下AI源文件转photoshop图像变模糊问题的解决教程,各位想知道具体解决方法的使用者们,那么下面就快来跟着小编...2016-09-14
  • Zend studio文件注释模板设置方法

    步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
  • C++万能库头文件在vs中的安装步骤(图文)

    这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
  • php文件上传你必须知道的几点

    本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
  • ant design中upload组件上传大文件,显示进度条进度的实例

    这篇文章主要介绍了ant design中upload组件上传大文件,显示进度条进度的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-29
  • C#使用StreamWriter写入文件的方法

    这篇文章主要介绍了C#使用StreamWriter写入文件的方法,涉及C#中StreamWriter类操作文件的相关技巧,需要的朋友可以参考下...2020-06-25
  • php实现文件下载实例分享

    举一个案例:复制代码 代码如下:<?phpclass Downfile { function downserver($file_name){$file_path = "./img/".$file_name;//转码,文件名转为gb2312解决中文乱码$file_name = iconv("utf-8","gb2312",$file_name...2014-06-07
  • php跨网站请求伪造与防止伪造方法

    伪造跨站请求介绍伪造跨站请求比较难以防范,而且危害巨大,攻击者可以通过这种方式恶作剧,发spam信息,删除数据等等。...2013-10-01