I m just renaming file in directory....
...bt my files got duplicate...
due to duplicate .... some file get deleted...
I have an issue in my script...
bt im unable to solve this..
my script---
for($i=2;$i<=count($worksheet);$i++)
{
$directory = $_SERVER['DOCUMENT_ROOT'].'/mesleep/uploaded_files/test/';
$sku = (!isset($worksheet[$i][1])) ? '' : addslashes(trim($worksheet[$i][1]));
$image_1 = (!isset($worksheet[$i][2])) ? '' : htmlentities(trim($worksheet[$i][2]));
rename($directory.$image_1,$directory.$sku.'_'.$i);
$image_2 = (!isset($worksheet[$i][3])) ? '' : htmlentities(trim($worksheet[$i][3]));
rename($directory.$image_2,$directory.$sku.'_'.$i);
}
how can i make my image name unique...
试试这个http://php.net/manual/en/function.uniqid.php这将有助于提供唯一的字符串。
$uniqueString = uniqid(random(),true);
There are many ways to do so :
You can add time() before name.
Example:
$imageName="XYZ.png";
$uniqueImageName=time().$imageName; //Add time stamp before name to give image a unique name
In case assign name in loop, concatenate extra value with increament.
Like :
for($i=1;$i<=$lengthOfLoop;$i++)
{
$imageName="XYZ.png";
$uniqueImageName=time().$i.$imageName; //Add time stamp before name to give image a unique name
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.