could someone help me to get better ideas on how to re-write this.
This function is supposed to delete all the user's images from the /images dir when i delete a user's account but it's not working.
The images are store by user ID number in the /images dir like id 2 's pics would be 2_1.jpg , 2_2.jpg .. and so on.
Id like to make this function delete ALL the user's pics from the /images dir . Obviously their is somthing wrong with this.
function del_image($id){
global $tb_users, $base_path, $image_path;
$sql = "
select
total_files
from
$tb_users
where
id = '$id'
";
$query = mysql_query($sql) or die(mysql_error());
$number = mysql_result($query, 0, "total_files") + 1;
if ($number > 1)
{
for($i=1;$i<$number;$i++)
{
$image1 = $image_path . "/" . $id . "_" . $i . ".jpg";
$image2 = $image_path . "/" . $id . "_" . $i . ".JPG";
$image3 = $image_path . "/" . $id . "_" . $i . ".JPEG";
$image4 = $image_path . "/" . $id . "_" . $i . ".jpeg";
$image5 = $image_path . "/" . $id . "_" . $i . ".png";
$image6 = $image_path . "/" . $id . "_" . $i . ".PNG";
if (file_exists($image1))
{
$file = $image1;
}
elseif (file_exists($image2))
{
$file = $image2;
}
elseif (file_exists($image3))
{
$file = $image3;
}
elseif (file_exists($image4))
{
$file = $image4;
}
elseif (file_exists($image5))
{
$file = $image5;
}
elseif (file_exists($image6))
{
$file = $image6;
}
if(!empty($file)){
if(unlink($file)){
$k = 1;
} else return "An error occured, your image was not deleted.";
}
$file = "";
}
}
else
{
return "$number Could not delete image, no image was found.";
}
if (!empty($k))
{
drop_rotation($id);
set_notfound_image($id);
return "Your image has been deleted.";
}
}
Any help is needed. Thank you