PHP 图片 平均分割$filename = 'D://WWW/1.jpg';
$p = 5;
// Get new sizes
list($width, $height) = getimagesize($fi
php数组删除元素后重新索引
array_values()
函数返回一个包含给定数组中所有键值的数组,但不保留键名
PHP 图片 平均分割
$filename = 'D://WWW/1.jpg'; $p = 5; // Get new sizes list($width, $height) = getimagesize($filename); $newwidth = $width; $newheight = floor($height / $p); $last = $height % $p; // Load $source = imagecreatefromjpeg($filename); for( $i=0 ; $i< $p; $i++ ){ $_p = $newheight*$i; if( ( $i + 1 ) == $p ) $newheight += $last; $thumb = ImageCreateTrueColor($newwidth, $newheight); imagecopyresized( $thumb, $source, 0, 0, 0, $_p, $newwidth, $height, $width, $height); imagejpeg( $thumb , "./t{$i}.jpg" ,100); }
php 取出数组的最后一个元素
$items数组('0'=>a,'1'=>b,'2'=>c)里有这三个元素
取出$items数组的最后一个元素,可以用end()函数
$i=end($items);
$i就是$items里的最后一个元素
【php】读取"文件列表"按时间显示,并递归显示各层目录
1.读取该php所在目录的文件列表,用"修改时间、文件名"做键值对,塞入数组。对"修改时间"倒序。(貌似不能直接按时间倒序读取文件列表,此处为间接方法)
2.读取的若为文件直接输出,为目录就输出目录并递归扫描其下文件。
<?php //遍历当前目录下所有文件的和目录,并以树装形式显示 //1.打开目录句柄,获取句柄资源 //2.读取句柄资源,并显示当前和子目录下的(目录和文件名称) function getDirFile($path){ if(!($file_handler=opendir($path))) return; $fileNTimes=array(); //遍历-当前目录的"文件",排除该php文件 while(false !== ($file=readdir($file_handler))){ if($file=='.' || $file=='..' || $file=='index.php') continue; $fileNTimes[filemtime($path.'/'.$file)]=$file; } //倒序 krsort($fileNTimes); foreach ($fileNTimes as $mtime=>$file) { $file_path="$path/$file"; //路径 $rel_path=str_replace(__DIR__."/", "", $file_path); //相对路径 //若为-目录 if(is_dir($file_path)){ //根据"目录级别"缩进 if(substr_count($file_path,"/")>1){ $count=str_repeat(" ",substr_count($file_path,"/")); echo $count.'+'.$file; }else{ echo '+'.$file; } echo "<br/>"; getDirFile($file_path); } //若为-文件 else{ if(substr_count($file_path,"/")>1){ $count=str_repeat(" ",substr_count($file_path,"/")); echo $count.getFile_html($rel_path,$file).getTime_html($mtime); }else{ echo getFile_html($file,$file).getTime_html($mtime); } echo "<br/>"; } } } function getTime_html($time){ return '<a style="font-size:10px;color:grey"> '.date('(Y-m-d H:m:s)',$time).'</a>'; } function getFile_html($rel_path,$file){ return '<a href="'.$rel_path.'">'.$file.'</a>'; } //----------------------------------------- $path=__DIR__; getDirFile($path); ?>
php删除文件夹及其文件夹下所有文件
<? function deldir($dir) { //先删除目录下的文件: $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." && $file!="..") { $fullpath=$dir."/".$file; if(!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } } closedir($dh); //删除当前文件夹: if(rmdir($dir)) { return true; } else { return false; } } ?>
下一篇:阿里巴巴排名查询工具
评论列表
发表评论
热评文章
相关阅读