Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP หา Root Directory Path ของโปรเจกต์

เพื่อหา Root Directory Path สามารถใช้ __DIR__ หรือ dirname()

ไวยากรณ์แรก

echo __DIR__;

ไวยากรณ์ที่สอง

echo dirname(__FILE__);

ทั้งสองวิธีจะให้ผลลัพธ์เหมือนกัน

ตัวอย่างโค้ด

<!DOCTYPE html> <html> <body> <?php echo dirname(__FILE__); echo "<br>"; echo __DIR__; ?> </body> </html>

ผลลัพธ์

/home/KOq8Zd /home/KOq8Zd