Solved

extract path from file path in php

Posted on 2011-03-25
8
394 Views
Last Modified: 2012-05-11
How can I extract the path from a path to a file in php?
The path could be either UNC or local path so either \ or /
0
Comment
Question by:NewtonianB
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35220006
I putted this together,
let me know if this doenst work for you because of some other demands:

preg_match('#(.*)' . DIRECTORY_SEPARATOR . '.*$#', $_SERVER['SCRIPT_FILENAME'], $aMatch);
echo $aMatch[1];

Open in new window

0
 

Author Comment

by:NewtonianB
ID: 35220014
Thanks Rik and how would I find the directory seperator?
0
 
LVL 8

Assisted Solution

by:Rik-Legger
Rik-Legger earned 50 total points
ID: 35220021
You don't need to find it,
it is an PHP constant which is filled with the right seperator.
No need to find it out for yourselff.
Works out of the box :)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:NewtonianB
ID: 35220038
Ah ok, I just tried but it gives me back the entire path
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35220044
Can you show me the result you get?
0
 
LVL 5

Accepted Solution

by:
tsmgeek earned 450 total points
ID: 35220047
0
 

Assisted Solution

by:NewtonianB
NewtonianB earned 0 total points
ID: 35220057
fantastic tsmgeek works in all my scenarios thanks
0
 

Author Closing Comment

by:NewtonianB
ID: 35252829
thanks!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question