嘿,我试图在上传时更改文件名,如果它存在,但似乎我有问题。这是代码..
$tempfilename = $filename["name"];
while(file_exists($location . $tempfilename))
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$shuffled = str_shuffle($chars);
$stringa = substr($shuffled,0,7);
move_uploaded_file($filename["tmp_name"], $location . $filename["name"]);
$tempfilename = $stringA.$filename["name"];
}
move_uploaded_file($filename["tmp_name"], $location.$stringa.$filename["name"]);
clearstatcache();
这似乎不起作用
不知道我错过了什么。
答案 0 :(得分:1)
PHP变量名称区分大小写。
$stringA !== $stringa
然而,你是否考虑过只使用一个计数器,而不是所有乱七八糟的字符串呢?
$tempfilename = $filename["name"];
for ($i = 0; file_exists($location . $tempfilename); $i++) {
$tempfilename = $i . $filename["name"];
}
move_uploaded_file($filename["tmp_name"], $location . $tempfilename);