...

View Full Version : rename()



SeeIT Solutions
06-12-2005, 10:06 AM
I'm trying to use rename to rename a list of files to the md5 of the same thing.

Here is the code


for($i = 1;$i < 124;$i++) {
if (rename("image_".$i.".jpg",.md5("image_".$i).".jpg")) {
echo "$i done1<br>";
}
}

It keeps returning this error (124 times).


Warning: rename(image_1.jpg,09c8440f6189657b3d096c0af86c07c8.jpg): No such file or directory in /home/user/public_html/images/a.php on line 24

But the files do exist. Anyone know the problem? I don't want to have to rename 124 file :confused:

gsoft
06-12-2005, 10:17 AM
for($i = 1; $i < 124; $i++)
{
if (file_exists("image_".$i.".jpg"))
{
if (rename("image_".$i.".jpg", md5("image_".$i).".jpg"))
{
echo "$i done1<br>";
}
}
else
{
echo "File: (image_".$i.".jpg) doesnt exist"
}
}


You may also want to try the absolute path as well.

Serex
06-12-2005, 12:01 PM
i personally dont like hard coding values into a loop as well. means you have to change it everytime you add something...

if you can id try do a count on all items your looping through before you actually do the loop. store the number in a var then go

for($i = 1; $i < $num; $i++)

will work out easier in the long run

SeeIT Solutions
06-12-2005, 01:30 PM
I solved it.

The script was only gonna be run once, i changed the way my site was working and had to encode the way images were stored.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum