رفتن به مطلب

نمایش ندادن فایل های مورد نظر در این تابع


پست های پیشنهاد شده

سلام

تابعی که در زیر قرار دادم تمامی محتویات یک فولدر رو نشون می ده ، حالا مشکل همین جاست که من می خواهم تعدادی فایل و پوشه رو به دلخواه نشون ندهد ، یعنی تمامی محویات یک فولدر به جز اون هایی که بهش می گیم رو نشون بدهد.

<?php
// open the current directory
$dhandle = opendir('.');
// define an array to hold the files
$files = array();

if ($dhandle) {
// loop through all of the files
while (false !== ($fname = readdir($dhandle))) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if (($fname != '.') && ($fname != '..') &&
($fname != basename($_SERVER['PHP_SELF']))) {
// store the filename
$files[] = (is_dir( "./$fname" )) ? "{$fname}" : $fname;
}
}
// close the directory
closedir($dhandle);
}

echo "\n";
// Now loop through the files, echoing out a new select option for each one
foreach( $files as $fname )
{
echo "<img src='http://cdn3.iconfinder.com/data/icons/fatcow/32x32_0440/folder.png' style='margin-bottom:-10px;'/> <a href='{$fname}'>{$fname}</a>\n <br />";
}
echo "\n";
?>

لینک به ارسال

نام فایلها را در متغییر آرایه‌ای exclude قرار دهید


<?php
// open the current directory
$dhandle = opendir('.');
// define an array to hold the files
$files = array();
$exclude = array('a','d');

if ($dhandle) {
// loop through all of the files
while (false !== ($fname = readdir($dhandle))) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if (($fname != '.') && ($fname != '..') && ($fname != basename($_SERVER['PHP_SELF'])) && (! in_array($fname, $exclude))) {
// store the filename
$files[] = (is_dir( "./$fname" )) ? "{$fname}" : $fname;
}
}
// close the directory
closedir($dhandle);
}

echo "\n";
// Now loop through the files, echoing out a new select option for each one
foreach( $files as $fname )
{
echo "<img src='http://cdn3.iconfinder.com/data/icons/fatcow/32x32_0440/folder.png' style='margin-bottom:-10px;'/> <a href='{$fname}'>{$fname}</a>\n <br />";
}
echo "\n";
?>

  • امتیاز 2
لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...