English 中文(简体)
更名为“C”的工厂制造了杂草吗?
原标题:php rename behaving weird?

i) 具有绝对无改动的文字:

<?
chdir("data");
$files = glob("*");
shuffle($files);
var_dump($files);
$i=0;
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
foreach($files as $file) {
  $i++;
  $k = $i;
  $mime = finfo_file($finfo, $file);
  if(strpos($mime,"gif") !== false) {
    $ext = "gif";
  } else {
    $ext = "jpg";
  }
  if($k < 10) {
    $k = "00".$k;
  } else if($k < 100) {
    $k = "0".$k;
  }
  $k = $k.".".$ext;
  rename($file,$k);
  echo $k."
";
}

the folder data has some image files (jpg and gif) in it. but when i run it, suddenly a lot of images are just gone! 2/3rd of the images just got deleted... i don t understand how? i have an ext3 filesystem and PHP 5.3.2

最佳回答

我可以看看一下《法典》中什么会最终造成这种行为。 我认为最可能的原因或许是<代码>rename($file,$k);是已经存在的超额文件。 您可以补充以下规则:

if(file_exists($k.".".$ext)) {
    $k .= ".0" ;
}
while(file_exists($k.".".$ext)) {
    $k .= "0" ;
}
$k = $k.".".$ext;
rename($file,$k);

我的另一种想法是,或许有些东西与<代码>chdir(“数据”)

问题回答

你们是否驾d了吗?

第一次把所有图像重新命名为0001.jpg-00nn.jpg。 第二次开脱笔,因为来源名称和目标名称会重叠,例如,它更名为0042.jpg至0001.jpg,因此现有0001.jpg消失。

如果在将账单重新命名为k美元之前存在美元,则检查是否好:

if(!is_file($k)) {
    rename($file, $k);
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签