Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多个图像重命名&;用PHP上传_Php - Fatal编程技术网

多个图像重命名&;用PHP上传

多个图像重命名&;用PHP上传,php,Php,我使用以下代码将图像集上载到服务器,我在上载时重命名文件,但当我尝试上载多个文件时,它会自动替换文件,而我需要在文件名的末尾使用2、3、4等命名其他文件 <input type="file" name="upl" /> <input type="submit" value="submit" /> 例如,如果随机字符串是jahkhakshdkjshdjksahds,我需要将图像命名为jahkhakshdkjshdjksahds1.ext、jahkhakshdkjsjksa

我使用以下代码将图像集上载到服务器,我在上载时重命名文件,但当我尝试上载多个文件时,它会自动替换文件,而我需要在文件名的末尾使用2、3、4等命名其他文件

<input type="file" name="upl" />
<input type="submit" value="submit" />

例如,如果随机字符串是jahkhakshdkjshdjksahds,我需要将图像命名为jahkhakshdkjshdjksahds1.ext、jahkhakshdkjsjksahds2.ext、jahkhakshdkjshdjksahds3.ext、jahkhakshdkjshdjksahds4.ext、jahkhakshdkjsjksahds5.ext,同样地?

在越权前测试现有文件

...
$ext = findexts ($_FILES['upl']['name']) ; 
$ran = $_SESSION['imgrand'];
$target = "uploads/".$ran;

for($i=1;$i < 100;$i++) {
  $filename = $target.$i.".".$ext;
  if (file_exists($filename)) {
    continue;
  } else {
    if(move_uploaded_file($_FILES['upl']['tmp_name'], $filename)) 
    {
    echo "The file has been upl as : ".$filename;
    break; 
    } 
    else
    {
    echo "Sorry, there was a problem uploading your file: ".$filename;
    break;
    }
  } // not file_ex
} // for
...
。。。
$ext=findexts($_文件['upl']['name']);
$ran=$\会话['imgrand'];
$target=“uploads/”$ran;
对于($i=1;$i<100;$i++){
$filename=$target.$i.“..$ext;
如果(文件_存在($filename)){
继续;
}否则{
如果(移动上传的文件($文件['upl']['tmp\U名称],$filename))
{
echo“文件已上载为:”.$filename;
打破
} 
其他的
{
echo“抱歉,上载文件时出现问题:”.$filename;
打破
}
}//不是文件
}//为了
...
...
$ext = findexts ($_FILES['upl']['name']) ; 
$ran = $_SESSION['imgrand'];
$target = "uploads/".$ran;

for($i=1;$i < 100;$i++) {
  $filename = $target.$i.".".$ext;
  if (file_exists($filename)) {
    continue;
  } else {
    if(move_uploaded_file($_FILES['upl']['tmp_name'], $filename)) 
    {
    echo "The file has been upl as : ".$filename;
    break; 
    } 
    else
    {
    echo "Sorry, there was a problem uploading your file: ".$filename;
    break;
    }
  } // not file_ex
} // for
...