djsaeedkhan
دوشنبه 26 دی 1390, 01:04 صبح
با سلام خدمت دوستان
اول از همه بگم این کد ها مال من نیست و من کد هایی که در پروزه هام ازشون استفاده می کنم رو میذارم اینجا تا همه بتونن استفاده کنن
ما چند تا دستور داریم که با اون ها می تونیم روی فولد ها مدیریت داشته باشیم
از جمله:
opendir()
readdir()
closedir()
برای اینکه محتویات یه فولدر رو بخونیم و نمایش بدیم از این کد ها استفاده می کنیم. البته شما اگر بصورت تابع بنویسید می تونید کاریش کنید که با ارسال نام فولدر محتویات اون رو نمایش بده و بصورت لینک باشن و دوباره وقتی رو نام زیر فولدر کلیک شد زیر مجموعش رو هم نشون بده.
<?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" )) ? "(Dir) {$fname}" : $fname;
}
}
// close the directory
closedir($dhandle);
}
echo "<select name=\"file\">\n";
// Now loop through the files, echoing out a new select option for each one
foreach( $files as $fname )
{
echo "<option>{$fname}</option>\n";
}
echo "</select>\n";
?>
با کد زیر می تونید محتویات یه فولدر رو بصورت لیست باکس نمایش بدید.
<?php
echo "<select name=\"file\">\n";
foreach (new DirectoryIterator('.') as $file) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) {
echo "<option>";
// if the element is a directory add to the file name "(Dir)"
echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename();
echo "</option>\n";
}
}
echo "</select>\n";
?>
اول از همه بگم این کد ها مال من نیست و من کد هایی که در پروزه هام ازشون استفاده می کنم رو میذارم اینجا تا همه بتونن استفاده کنن
ما چند تا دستور داریم که با اون ها می تونیم روی فولد ها مدیریت داشته باشیم
از جمله:
opendir()
readdir()
closedir()
برای اینکه محتویات یه فولدر رو بخونیم و نمایش بدیم از این کد ها استفاده می کنیم. البته شما اگر بصورت تابع بنویسید می تونید کاریش کنید که با ارسال نام فولدر محتویات اون رو نمایش بده و بصورت لینک باشن و دوباره وقتی رو نام زیر فولدر کلیک شد زیر مجموعش رو هم نشون بده.
<?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" )) ? "(Dir) {$fname}" : $fname;
}
}
// close the directory
closedir($dhandle);
}
echo "<select name=\"file\">\n";
// Now loop through the files, echoing out a new select option for each one
foreach( $files as $fname )
{
echo "<option>{$fname}</option>\n";
}
echo "</select>\n";
?>
با کد زیر می تونید محتویات یه فولدر رو بصورت لیست باکس نمایش بدید.
<?php
echo "<select name=\"file\">\n";
foreach (new DirectoryIterator('.') as $file) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) {
echo "<option>";
// if the element is a directory add to the file name "(Dir)"
echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename();
echo "</option>\n";
}
}
echo "</select>\n";
?>