作者:陳業貴 華為雲享專家 51cto(專家部落客 明日之星 TOP紅人) 阿裡雲專家部落客
文章目錄
- cyg.php
cyg.php
<?php
//指定檔案路徑
$arr = glob("D:/phpstudy_pro/WWW/images/*.png");//函數傳回比對指定模式的檔案名或目錄。
$i=1;
//循環周遊
foreach($arr as $file) {
//$file是D:/phpstudy_pro/WWW/images/16449 (1).png
//擷取圖檔字尾名
$ext = pathinfo($file,PATHINFO_EXTENSION);
$name = pathinfo($file)['filename'];//擷取檔案名
//重命名
echo rename($name.".".$ext,++$i.".".$ext);
}
運作後的效果: