php高手们,用php怎么改文件名?

php高手们,用php怎么改文件名?,第1张

php手册:

bool rename ( string oldname, string newname [, resource context] )

尝试把 oldname 重命名为 newname。

如果成功则返回 TRUE,失败则返回 FALSE。

例子:

rename( 'tempFile.txt', 'tempFile2.txt' )

$name=$shareInfo['name']

$pos=strrpos($name,".")//右侧查找'.'的位置

//组合条件只处理jpg/png类型的

if($pos &&(substr($name,$pos+1)=="jpg" || substr($name,$pos+1)=="png")){

    echo substr($name,0,$pos)

}

方法如下:我重命名的规则是把所有有空格的全部替换成“_”,然后再后面加一个"_s"。

<?php

$paths = "C://Documents and Settings//sk//Desktop//s//"

$d = dir($paths)

while (false !== ($entry = $d->read())) {

$table_change = array(' '=>'_')

$newName = strtr($entry,$table_change)

$newName = substr($newName, 0,-4)

rename($paths.$entry, $paths.$newName."_s.jpg")

}

$d->close()

echo "done"

?>

以上就是php如何批量修改某个文件夹下所有文件名的方法


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/6040283.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-12
下一篇 2023-03-12

发表评论

登录后才能评论

评论列表(0条)

保存