Avatar of sasnaktiv
sasnaktiv
Flag for United States of America asked on

How can I get just the filename of the originating document?

How can I get just the filename of the originating document?
$ref=@$_SERVER[HTTP_REFERER]; gives me the full http path
$ref=@$_SERVER[REQUEST_URI]; gives me the /directoryname/filename
I only want the filename. Nothing else.
Can you help?
Thanks
Sas
PHP

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Dave Baldwin

On many servers, 'SCRIPT_NAME' gives you just the filename.  However, this is not guaranteed.  Each server and admin may provide a different set of values because they all come from the server.

http://php.net/manual/en/reserved.variables.server.php

I use this program to see what my servers provide.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>PHP Server Variables</title>
</head>
<body>
<h1>PHP Server Variables</h1>
<?php

//reset($_SERVER);
foreach($_SERVER as $key => $value) {
    echo "<b>$key :</b> $value<br />\n";
}
?>
</body>
</html>

Open in new window

sasnaktiv

ASKER
Thanks for your quick response Dave,
Your list gives me a lot of information that I'm not looking for.
And it doesn't give me the simple, isolated filename that I am looking for.
I just want the 'filename' not its directory, not its path.
Can you isolate the 'filename'?
Sas
Dave Baldwin

Apparently not.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
sasnaktiv

ASKER
So much for PHP.
Do you know how I can delete everything before the 'filename'?
That might be a solution.
Thanks for the help, Dave
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
sasnaktiv

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
sasnaktiv

ASKER
Much appreciated, Dave.
Sas
Dave Baldwin

You're welcome.  You said 'originating document' and I thought you meant the name of the page.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.