Solved

extract path from file path in php

Posted on 2011-03-25
8
368 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
 

Author Comment

by:NewtonianB
ID: 35220038
Ah ok, I just tried but it gives me back the entire path
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now