Combine Directory and File Name in PHP ( equivalent of Path.Combine in .Net) -


This should be a simple question, but I just can not remember the related API. A search on Google with the word "does not produce any results". So I think I am doing a service by asking myself and the programming community by asking this question.

How to combine directories and file names to create full file paths in PHP? Assume that the directory name is " D: \ setup program ", and the file name is " mj.txt ". Method should be returned to me, Windows " D: \ Setup program \ mj.txt ". Definitely the method should return the correct file path to Linux or other OS.

The related function in the net, but in PHP, I did not remember it, even if I had already seen it.

  $ filepath = $ path DIRECTORY_SEPARATOR $ file;  

Although it does not matter in new versions of PHP how slash is, so it is OK to always use forward slash.

By using the perfect full path, you will remove things like this extra unnecessary slash and solve references like ../ . If the path is not valid then it will return false.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -