PDA

View Full Version : Pulling something out of a filename...



Dentafrice1
25-09-2006, 08:43 PM
Say I have this directory... /avatars/

and there is no file in there but my php file which displays that persons avatar...

I need to be able to pull this out of the url:

http://www.sitename.com/avatars/username.gif

I need to pull username out of the url.. using that PHP file.. thats the only thing in the directory.. it takes and pulls the username.. querys the database for that user. And displays it from /images/

Any ideas on how to do that?

Kymux
25-09-2006, 09:12 PM
Isnt that just simple variables ?

Dentafrice1
25-09-2006, 09:16 PM
Not sure.. but but its not a $_GET i don't think as your not going to bla.php?name=hey your going to /name.gif

Splinter
26-09-2006, 10:46 AM
if you just get the filename.. such as me.gif
then use:


$name = basename("me.gif");

that should remove the .gif I think..

RYANNNNN
26-09-2006, 02:53 PM
well just do something like this then ..
$profile[name].gif

Kymux
26-09-2006, 03:14 PM
Yeah that would be good. Set the variable to name and use

$profile[name].gif

Dentafrice1
26-09-2006, 07:55 PM
there is no gif file.. I just need to pull the info out of the url

nets
26-09-2006, 08:00 PM
there is no gif file.. I just need to pull the info out of the url
So you want a PHP script which obtains a variable containing what's after the forward slash?

Dentafrice1
26-09-2006, 08:07 PM
Yes.. I have say

www.site.com/images/Kevin.gif (My avatar)

I need to have my PHP script pull 1 out of this:
http://www.site.com/avatar/1.gif (1 = MY ID)

YouFail
26-09-2006, 08:07 PM
Im not 100% sure what you mean. But wouldn't it be

www.sitename.com/?view=/$profile[image]

As the link so that you could get a profile image for that person

The link would then be

<a href=\"/$profile[image]\">Link</a>

Im not 100% sure if this is helpful at all.

Dentafrice1
26-09-2006, 08:08 PM
no thats not it..

nets
26-09-2006, 08:18 PM
I can write you a script where your domain will look something similar to:-

http://example.com/example.php/example.gif


<?php

if($_SERVER['PATH_INFO'])
{
$id = $_SERVER['PATH_INFO'];
$id{0} = null; //null slash
$id = preg_replace('/\..*$/', '', $id);

}

?>

Haven't tested.

Jamie.
26-09-2006, 08:21 PM
looks kinda dodgy that script :s

Dentafrice1
26-09-2006, 08:22 PM
but I found a website, which he does probably not want me to give it out but he has a url

site.com/bla/

Only file in that directory: bla.php

If you go to site.com/bla/bla.gif

It uses gd librarys to make something..

nets
26-09-2006, 08:23 PM
Why don't you ask him?

Edit:- Perhaps it's using a PHP script as the 404 page?


looks kinda dodgy that script :s
Maybe if you're an idiot.

Jamie.
26-09-2006, 08:25 PM
a code not a script,

CALL ME A IDIOT? TAKE A LOOK IN A MIRROR!

nets
26-09-2006, 08:36 PM
CALL ME A IDIOT?
No, I was calling you an idiot.

Dentafrice1
26-09-2006, 08:37 PM
QUIT FIGHTING AND HELP ME! :P

Jamie.
26-09-2006, 08:42 PM
thght u php brainiac

Dentafrice1
26-09-2006, 08:47 PM
I am but I can't figure this out :\

Jamie.
26-09-2006, 08:50 PM
hmmm, i think its similar to..... the php skinning tut halting made on techtuts

where it grabbed the skin from url like :

index1.php?skin=green << so basically that wud be summin like

index1.php?User=Jamie.
i dno ask halting he may no :)

Dentafrice1
26-09-2006, 08:56 PM
Someone already said that.. if you would read the posts..


its a folder with a filename in it.. you dont go to the filename at all it goes to a fake gif file

nets
26-09-2006, 09:13 PM
Just have this in a .htaccess file in your directory:

ErrorDocument 404 /index.php

& have index.php using php self to get the data you want.


I am
ERM? Lol

Want to hide these adverts? Register an account for free!