FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » scandir problem
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
scandir problem [message #185702] Sat, 03 May 2014 15:43 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
http://www.php.net/manual/en/function.scandir.php

Using their method, what is the proper way to insert a variable within the
url?

e.g.
http://www.something.com/dir/$variable

Is the ending / needed?
this does not work.
$dir="http://www.something.com/dir/$variable"
$dir="http://www.something.com/dir/".$variable
Re: scandir problem [message #185703 is a reply to message #185702] Sat, 03 May 2014 16:08 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Sat, 3 May 2014 11:43:45 -0400, richard wrote:

> http://www.php.net/manual/en/function.scandir.php
>
> Using their method, what is the proper way to insert a variable within the
> url?
>
> e.g.
> http://www.something.com/dir/$variable
>
> Is the ending / needed?
> this does not work.
> $dir="http://www.something.com/dir/$variable"
> $dir="http://www.something.com/dir/".$variable

I did get it working by using the ".." before the path.
Apparently, the full url method does not work in this case.
Re: scandir problem [message #185711 is a reply to message #185703] Sat, 03 May 2014 22:11 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Sat, 03 May 2014 12:08:18 -0400, richard wrote:

> On Sat, 3 May 2014 11:43:45 -0400, richard wrote:
>
>> http://www.php.net/manual/en/function.scandir.php
>>
>> Using their method, what is the proper way to insert a variable within
>> the url?
>>
>> e.g.
>> http://www.something.com/dir/$variable
>>
>> Is the ending / needed?
>> this does not work.
>> $dir="http://www.something.com/dir/$variable"
>> $dir="http://www.something.com/dir/".$variable
>
> I did get it working by using the ".." before the path. Apparently, the
> full url method does not work in this case.

The problem that you encountered is not the problem that you stated it
was. Your error[1] was the failure to understand the difference between
an http url and a filesystem path.

The webserver translates the http url to the filesystem path, where the
"root" directory of the webserver "www.something.com" might be at a file
path that looks something like "/users/s/something.com/http/"

For example, on a fasthosts uk server, using apache, the root of the http
files is available as: {$_SERVER["DOCUMENT_ROOT"]}

Your problem is that you were trying to use a url as a filepath.

What you need to do is take the url:

http://www.something.com/dir/

replace the part: "http://www.something.com" with "{$_SERVER
["DOCUMENT_ROOT"]}"

then append the path part of the url: "/dir/"

then append your $variable

To generate:

$dir = "{$_SERVER["DOCUMENT_ROOT"]}/dir/{$variable}"

[1] otherwise known as yet another richardian fuckup

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Storing strings and numbers properly in CSV files
Next Topic: count() problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 12:52:34 GMT 2024

Total time taken to generate the page: 0.02237 seconds