Jump to content

[SOLVED] Get a file name from a path


d22552000

Recommended Posts

Yes, this is almost like PARSE_URL, but no this is not what I want to do.

 

Simplest way to explain it is by example.

 

I want to turn this:

./`admin/plugins/top/*.php

Into this:

*

 

I want to get the name of the script IN the file.  The files PATH, is not going to be /`admin/plugins/top/.

The paths will be ./`admin/plugins/*  (top | middle | bottom).

 

How would I convert these names?

Link to comment
https://forums.phpfreaks.com/topic/77255-solved-get-a-file-name-from-a-path/
Share on other sites

nope, I am doing this:

 

Scanning a directory for files using glob

creating a header (h#) for them using their NAME

eval'ing these files to add them to this script im in.

 

ending that header block (/h#)

 

 

currently im doing this a very long way:

 

<?PHP

function parse_plugin($con,$file) {
    $file = str_replace('./`admin/plugins/','',$file);
    $file = str_replace('bottom','',$file);
    $file = str_replace('middle','',$file);
    $file = str_replace('top','',$file);
    $file = str_replace('.php','',$file);
    $file = str_replace('/','',$file);

    begin_frame($file,true);
     eval($con);
    end_frame();
}

foreach(glob('./`admin/plugins/top/*.php') as $file) {
  parse_plugin(file_get_contents($file),$file);
}

//--bunch of script--//

foreach(glob('./`admin/plugins/middle/*.php') as $file) {
  parse_plugin(file_get_contents($file),$file);
}

//--bunch of script--//

foreach(glob('./`admin/plugins/bottom/*.php') as $file) {
  parse_plugin(file_get_contents($file),$file);
}

?>

You really need to explain your question alot clearer. Given a filepath, basename returns the file name. eg;

 

#!/usr/bin/php
<?php

    foreach (glob('~/scratch/*.php') as $filepath) {
        echo "$filepath : " . basename($filepath) . "\n";
    }  

?>

 

returns....

 

/home/thorpe/scratch/abs.php : abs.php
/home/thorpe/scratch/ch.php : ch.php
/home/thorpe/scratch/filter.php : filter.php

 

on my machine.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.