How to get the directory name out of a file path name?



How to get the directory name out of a file path name?..

Answer / Rajni Pandey

In PHP, you can use the pathinfo() function to extract the directory name from a file path. Here's an example: `$filePath = "/var/www/example.com/files/myfile.txt"; $pathInfo = pathinfo($filePath); echo $pathInfo['dirname']; // Output: /var/www/example.com/files

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

Can we use php variable in javascript?

1 Answers  


What is php mean?

1 Answers  


Which is a perfect example of runtime polymorphism?

1 Answers  


What is php in simple words?

1 Answers  


What is the difference between $_files['userfile']['name'] and $_files['userfile']['tmp_name']?

1 Answers  


Write a hello world program using variable?

1 Answers  


What type of operation is needed when passing values through a form or an url?

1 Answers  


How to open a file in php?

1 Answers  


Which function will you use to create an array?

1 Answers  


Why use static methods php?

1 Answers  


What does == mean in php?

1 Answers  


Write a program to find no of days between two dates in php?

1 Answers  


Categories