r3p0 Posted May 20, 2009 Share Posted May 20, 2009 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 More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 Look into the pathinfo function. Link to comment https://forums.phpfreaks.com/topic/158955-insert-current-file-name/#findComment-838327 Share on other sites More sharing options...
r3p0 Posted May 20, 2009 Author Share Posted May 20, 2009 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. Link to comment https://forums.phpfreaks.com/topic/158955-insert-current-file-name/#findComment-838422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.