hi everyone,
I'm having a very strange problem that has me stompt. I have a number of images named 1.jpg,2.jpg,3.jpg.... These images are images of articles in a store there corresponding title and description are stored in a database. Now i am working on a script to delete an image from the folder but then al the images that follow that images need to be renamed(eg. deleting 2.jpg allso mean i have to rename 3.jpg to 2.jpg and so on).So what i did was create a function that takes in the nr of the picture you want to delete then it does unlink(thatpicture) and then i have a for loop that renames all following images. I tested the deleting first and that worked,then i tested the renaming seperatly and that worked too but when i combined them something very strange happened during the renaming the deleted image magicly reappears and becomes 2.jpg again and another image in the row dissappears.I know there is nothing wrong with the for loop that does the renaming because that allso deletes and changes the idnr of the data in the in database and that works fine. I really don't get what's going on.
here is the function🙁$categorie just specifies in wich folder the image is and what table the data is in there is nothing wrong with that)
function del_items($categorie,$index)
{
echo "Bezig met artikel te verwijderen:$categorie,$index<br>";
$del_file = "./img/$categorie/$index.JPG";
echo "Deleting $del_file<br>";
//delete file
unlink($del_file);
//delete the date from the database
$delquery= "DELETE FROM '$categorie' WHERE autoID='$index'";
mysql_query("DELETE FROM $categorie WHERE autoID='$index'")
or die(mysql_error());
if(!file_exists("./img/$categorie/$index.JPG"))
echo "Deleted $del_file";
for($renin=($index+1);file_exists("./img/$categorie/$renin.JPG"); $renin++)
{
//rename images
$orig_path = "./img/$categorie/$renin.JPG";
$renamein = $renin-1;
$renamed_path = "./img/$categorie/$renamein.JPG";
rename($orig_path,$renamed_path);
echo "renamed $orig_path to $renamed_path<br>";
//update autoID's in database
$upquery= "UPDATE $categorie SET autoID=$renamein WHERE autoID=$renin";
mysql_query($upquery) or die (mysql_error());
}