Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.