I’ve written a submit $_POST button that when submitted will run the following code. I’m trying to eliminate outdated avatars that DO NOT match the database values for current avatars. However, for whatever reason, it is not recognizing the files correctly once it reaches the foreach/unlink functions, it will either say that $variable is undefined or trigger the success message but unlink nothing. Up til then, it recognizes the array keys and values just fine. I’m wondering if its even trying to erase the right files, or if its attempting to unlink the matching database entries, despite the array_diff function. I could really use some help here…
[php]
$directory = $phpbb_root_path . ‘images/avatars’;
$avatar_files = scandir($directory);
$user_id = (int) $user->data[‘user_id’];
//SQL select query to select the row array for the current avatars value here (fully functional, echoed results to test this).
while($row = $db->sql_fetchrow($result))
{
$new_result = array_diff($row, $avatar_files);
foreach ($new_result as $key => $val)
{
$variable = $val;
$myFile = $phpbb_root_path . ‘images/avatars/’ . $variable;
if(is_string($myFile))
{
unlink($myFile);
}
}
trigger_error($user->lang['CONFIG_UPDA… . adm_back_link($this->u_action));
}[/php]