PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
this prevents the folders . and .. from beeing displayed. You need something similar for the file's extension (if you want to rely on the name). Instead of using more and more if-cases you might set up an array containing the allowed extensions
<?php
$allowedExtensions = array('.jpg', '.jpeg', '.png', '.bmp');
$dir = './'; // the trailing / is important to make $dir.$filename a valid path
$dh = opendir($dir); // open it for reading
while (($filename = readdir($dh)) !== false)
{ // loop files
if (is_file($dir.$filename)) // skip directories, filters out . and .. as well
{
$extension = strrchr($filename, '.');
if (in_array($extension, $allowedExtensions))
echo $filename, '<br />';
}
}
?>
this prevents the folders . and .. from beeing displayed. You need something similar for the file's extension (if you want to rely on the name). Instead of using more and more if-cases you might set up an array containing the allowed extensions
<?php
$allowedExtensions = array('.jpg', '.jpeg', '.png', '.bmp');
$dir = './'; // the trailing / is important to make $dir.$filename a valid path
$dh = opendir($dir); // open it for reading
while (($filename = readdir($dh)) !== false)
{ // loop files
if (is_file($dir.$filename)) // skip directories, filters out . and .. as well
{
$extension = strrchr($filename, '.');
if (in_array($extension, $allowedExtensions))
echo $filename, '<br />';
}
}
?>
ONE POSSIBLE ISSUE, DOES THAT INCLUDE CASES LIKE: BLAH.10.27.2003.JPG
sorry bout the caps, but i feel that if this is a newbie, it's important to point out that (s)he needs to think about little things like that
/mom/b-weed.jpg
Warning: rmdir(): SAFE MODE Restriction in effect. The script whose uid is 511 is not allowed to access / owned by uid 0 in /home/virtual/site9/fst/var/www/html/removep.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site9/fst/var/www/html/removep.php:2) in /home/virtual/site9/fst/var/www/html/removep.php on line 4
well removep.php is in my html folder.. then from there user cookie is the name of the folder in this case mom so: /mom/ then we have the file we want deleted.. which is weed-b.jpg so: /mom/weed-b.jpg
so the absolute path you want to access is /home/virtual/site9/fst/var/www/html/mom/b-weed.jpg?
If so try it without the leading / in rmdir("/" . $_COOKIE[user] . "/" .$_POST[delete]);
If I take away the "/" it says the directory doesn';t exsist.. so I think i should stick with the safe mode error cuz theres a solution to it somewhere.
Warning: unlink(/mom/avatar1.jpg): No such file or directory in /home/virtual/site9/fst/var/www/html/removep.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site9/fst/var/www/html/removep.php:2) in /home/virtual/site9/fst/var/www/html/removep.php on line 3
actually i was thinking preg_match('/\.jp(e|g)g?$/i' $file); sinve that makes it have to end with .jpe.jpg, jpeg since those are valid jpg extensions (yes thereis one fake extension that would be allowed.....jpgg)