Page 1 of 1

Cutting down a variable

Posted: Thu Aug 18, 2005 4:23 am
by crazycaddy
ok, basically I need a way to turn this:

Code: Select all

$file = C:/bla/bla/egg.zip
Into this:

Code: Select all

$folder = C:/bla/bla/
$filename = egg.zip
How would I go about doing this, this has to work for file names that are any length.

Posted: Thu Aug 18, 2005 4:50 am
by crazycaddy
This may not invlove php (i'm not sure) but is it possible to open for example my documents from a webpage? Ive tried a few ways but no luck, it either does nothing at all or just shows a page cannot be found message.

Posted: Thu Aug 18, 2005 4:56 am
by raghavan20
find the last occurence of '/' using regex and find the length of the string.
If you have the position of the last occurence of '/', then you can read each character from then to the length of the string - 1

Posted: Thu Aug 18, 2005 6:27 am
by timvw

Posted: Thu Aug 18, 2005 6:41 am
by raghavan20
this idea seems to be easier

Code: Select all

<?
$path = "/home/httpd/html/index.php";
$tempArray = explode("/", $path);
echo "filename:".$tempArray[count($tempArray) - 1];

?>

Posted: Thu Aug 18, 2005 6:45 am
by crazycaddy
raghavan20 wrote:this idea seems to be easier

Code: Select all

<?
$path = "/home/httpd/html/index.php";
$tempArray = explode("/", $path);
echo "filename:".$tempArray[count($tempArray) - 1];

?>
Works brilliant cheers, but unfortunatley its basically useless unless you can popup a local folder from a link or automatically.

Posted: Thu Aug 18, 2005 7:22 am
by raghavan20
not really understood wot you meant.
this is used to get the directory of a file path.

Code: Select all

<?
$path = "/home/httpd/html/index.php";
$tempArray = explode("/", $path);
echo "filename:".$tempArray[count($tempArray) - 1]."<br />";

for($i = 1; $i < count($tempArray) - 1; $i++)
	$dirPath .= "/".$tempArray[$i];
echo $dirPath;//prints directory path



?>
if you want the path of a currently running doc, use $_SERVER['DOCUMENT_ROOT']
look at $_SERVER globals for more options
http://uk.php.net/reserved.variables

Posted: Thu Aug 18, 2005 7:55 am
by crazycaddy
basically what I want is too very simply link to a folder on the users machine, eg if the user browses to the folder C:\stuff\ and submits then the script pops it open, I need to know how to open users folder from a webpage.