Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

extract path from file path in php

Posted on 2011-03-25
8
Medium Priority
?
437 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 1800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 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