gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php对读取的文件进行删除和获取文件图片操作实例代码详解

来源:http://erdangjiade.com/topic/1485.html 你好,世界。 2017-09-25 22:42浏览(8)

1. 删除文件

unlink()

语法: int unlink(string filename);

返回值: 整数

函数种类: 文件存取。如:

unlink("tmp/test.txt");

PHP按行读取文件 去掉换行符” ”:

$content=str_replace("
","",$content);
echo $content;

$content=str_replace(array("
","
"),"",$content);

$content=preg_replace("/s/","",$content);

$content=trim($content);

2. 获取文件夹下面的文件名

$dir = "message/"; // 文件夹的名称
if (is_dir($dir)){
  if ($dh = opendir($dir)){
    while (($file = readdir($dh)) !== false){
      echo "文件名: $file <br>";
    }
    closedir($dh);
  }
}

3. 读取文件夹下面的图片名

<?php
$handle = opendir('images/'); //当前目录
  while (false !== ($file = readdir($handle))) { //遍历该php文件所在目录
   list($filesname,$kzm)=explode(".",$file);//获取扩展名
    if($kzm=="gif" or $kzm=="jpg" or $kzm=="JPG") { //文件过滤
     if (!is_dir('./'.$file)) { //文件夹过滤
      $array[]=$file;//把符合条件的文件名存入数组
      $i++;//记录图片总张数
      }
     }
  }
 print_r($array);
?>

以上就是php对读取的文件进行删除和获取文件图片操作实例代码详解的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2