पीएचपी opendir () समारोह
उदाहरण
एक निर्देशिका खोलें, उसकी सामग्री पढ़ें, फिर बंद करें:
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
परिणाम:
filename: cat.gif
filename: dog.gif
filename: horse.gif
परिभाषा और उपयोग
opendir () फ़ंक्शन एक निर्देशिका हैंडल खोलता है।
वाक्य - विन्यास
opendir(path, context)
पैरामीटर मान
Parameter | Description |
---|---|
path | Required. Specifies the directory path to be opened |
context | Optional. Specifies the context of the directory handle. Context is a set of options that can modify the behavior of a stream |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | सफलता पर डायरेक्टरी हैंडल रिसोर्स लौटाता है। विफलता पर FALSE। यदि पथ एक वैध निर्देशिका नहीं है, या यदि अनुमति प्रतिबंध या फाइल सिस्टम त्रुटियों के कारण निर्देशिका को खोला नहीं जा सकता है, तो स्तर E_WARNING की त्रुटि फेंकता है। आप फ़ंक्शन नाम के सामने '@' जोड़कर opendir() के त्रुटि आउटपुट को छिपा सकते हैं |
---|---|
पीएचपी संस्करण: | 4.0+ |
पीएचपी चेंजलॉग: | PHP 5.0: पथ पैरामीटर अब ftp: // URL आवरण का समर्थन करता है |
पीएचपी निर्देशिका संदर्भ