Jump to content

Insert current file name?


r3p0

Recommended Posts

How can I make the current file name the result of a variable?

 

I am editing files at "htttp://www.acme.com/coyote/". I will need to work with "screwed.php", "blowedUp.php" & "determined.php" all within that "coyote" directory. Within each of those PHP files I'd like to set up a variable so that

$fileName = "current file name"

 

So, when working with "screwed.php", how do I make the $fileName variable automatically return "screwed"? (without the file extension) Or,

$fileName = 'screwed'

 

Maybe it has something to do with basename? That's as close as I got but can only get a path and not the file name.

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/158955-insert-current-file-name/
Share on other sites

Still, I have trouble returning the filename sans extension.

 

The example given is:

<?php
$path_parts = pathinfo('/www/htdocs/index.html');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?>

 

However, it seems that in order to return $fileName= 'screwed' I have to type in the path to "screwed.php".

pathinfo('coyote/screwed.php')

Moreover, I have to type the path to each of the different files within each of the files ("blowedUp.php" & "determined.php").

 

Any other clues to make PHP recognize the name of the file where it exists? This reminds me of shadows in a cave.

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.