Notice: Undefined index: i
Posted: Sun Dec 05, 2010 4:21 am
I have this php code to delete images from a folder at the user will:
And I am getting this warning:
( ! ) Notice: Use of undefined constant i - assumed 'i' in /home/nando/Websites/romario.home/delete_images.php on line 30.
Here, in my code, it is the code on this line:
Any help would be appreciated. Thanks in advance.
Code: Select all
<?php
$dir = 'dir_upload';
$array_imgs = scandir($dir);
for ($i = 0; $i < count($array_imgs); $i++) {
$arq = $array_imgs[$i];
if ($arq <> '.' && $arq <> '..') {
$ext = explode('.', $arq);
if (($ext[i] == 'gif') || ($ext[i] == 'jpg') || ($ext[i] == 'png')) {
echo("<div class='del_img'>");
echo("<a href='$dir/$arq' class='highslide' onclick='return hs.expand(this,
{wrapperClassName: \"wide-border\", captionOverlay: {position: \"rightpanel\"}})'>");
echo("<img src='$dir/$arq' height='200' width='200' alt='$arq'></a>");
/* Este 'file[]' é o que cria o array com o arquivos que tiveram o checkbox
* marcado. Assim podemos deletar vários arquivos de uma só vez. */
echo("<input type='checkbox' name='file[]' value='$arq'>");
// Fecha a div del_img.
echo("</div>\n");
}
}
}
}
// Lógica para deletar a imagem.
if (isset($_POST['file']) && is_array($_POST['file'])) {
foreach ($_POST['file'] as $file) {
if ($arq <> '.' && $arq <> '..') {
unlink("$dir/$file") or die(mysql_error());
/* redirect "'after'" deleting files so the user can refresh without that
* resending post info message. */
header("location: " . $_SERVER['REQUEST_URI']);
}
}
}
?>
</form>
( ! ) Notice: Use of undefined constant i - assumed 'i' in /home/nando/Websites/romario.home/delete_images.php on line 30.
Here, in my code, it is the code on this line:
Code: Select all
if (($ext[i] == 'gif') || ($ext[i] == 'jpg') || ($ext[i] == 'png')) {