Re: [PHP] Path question.

2011-07-28 Thread Richard Quadling
On 28 July 2011 13:36, Nilesh Govindarajan  wrote:
> On 07/28/2011 05:43 PM, Paul Halliday wrote:
>> I have a few scripts that use "../location/file"
>>
>> Is this interpreted differently on some systems?
>>
>> Thanks.
>>
>
> I have no idea about it, but I generally use realpath() to avoid any
> such problems. Windows may have, because it uses backward slashes
> instead of forward which are used in *nix (incl mac)

For PHP on Windows, the / is fine. Obviously, if you are going to be
calling OS based tools from PHP, you'll need to realpath() or use \\
or DIRECTORY_SEPARATOR.


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Path question.

2011-07-28 Thread Dajka Tamas
Yes, can be. There is a predefined variable DIRECTORY_SEPARATOR, which you
can use:

on index.php let's say
define('DS',DIRECTORY_SEPARATOR');
define('MY_APP_ROOT',dirname(realpath(__FILE__)));

define('LIB_DIR',MY_APP_ROOT.DS."..".DS."location".DS."file");

Cheers,

Tamas

-Original Message-
From: Paul Halliday [mailto:paul.halli...@gmail.com] 
Sent: Thursday, July 28, 2011 2:14 PM
To: PHP-General
Subject: [PHP] Path question.

I have a few scripts that use "../location/file"

Is this interpreted differently on some systems?

Thanks.

-- 
Paul Halliday
http://www.squertproject.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Path question.

2011-07-28 Thread vikash . iitb
On 28 July 2011 18:06, Nilesh Govindarajan  wrote:

> On 07/28/2011 05:43 PM, Paul Halliday wrote:
> > I have a few scripts that use "../location/file"
> >
> > Is this interpreted differently on some systems?
> >
> > Thanks.
> >
>

Use __DIR__."../location/file" otherwise files using these script can not be
moved across folders.


>
> I have no idea about it, but I generally use realpath() to avoid any
> such problems. Windows may have, because it uses backward slashes
> instead of forward which are used in *nix (incl mac)
>
> --
> Regards,
> Nilesh Govindarajan
> @nileshgr on twitter/identica
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Path question.

2011-07-28 Thread Nilesh Govindarajan
On 07/28/2011 05:43 PM, Paul Halliday wrote:
> I have a few scripts that use "../location/file"
> 
> Is this interpreted differently on some systems?
> 
> Thanks.
> 

I have no idea about it, but I generally use realpath() to avoid any
such problems. Windows may have, because it uses backward slashes
instead of forward which are used in *nix (incl mac)

-- 
Regards,
Nilesh Govindarajan
@nileshgr on twitter/identica

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Path question.

2011-07-28 Thread Paul Halliday
I have a few scripts that use "../location/file"

Is this interpreted differently on some systems?

Thanks.

-- 
Paul Halliday
http://www.squertproject.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Path question

2011-03-31 Thread tedd

At 9:18 PM -0400 3/28/11, Jack wrote:

Hello All,



Is there a smarter way to do includes by setting up a path or something
where I don't have to include /home/domain.com/includes/include_file.php

Apparently my path is as shown above,  but I would prefer to just put in
/includes/include_file.php

Thanks!

Jack



That's just a different between absolute and relative paths.

If you want to provide local files to a local script, then use 
"includes/include_file.php" -- that simply means in the same 
directory as the calling script there is a directory named "include" 
and within that directory is a file named "include_file.php".


Try it.

Sometimes people make this out to be harder than it is.

Cheers,

tedd
--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Path question

2011-03-30 Thread Richard Quadling
On 29 March 2011 19:41, D. Dante Lorenso  wrote:
> On 3/28/11 8:18 PM, Jack wrote:
>>
>> Hello All,
>> Is there a smarter way to do includes by setting up a path or something
>> where I don't have to include /home/domain.com/includes/include_file.php
>> Apparently my path is as shown above,  but I would prefer to just put in
>> /includes/include_file.php
>
> I wrote about this a long time ago ... perhaps it might help:
>
> http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/
>
> Talks about putting your functions into classes and using the autoloader to
> avoid putting include statements in your code.
>
> Might not help if you are loading content which is not just PHP
> functions/code, but if you haven't "evolved" this far yet, the read might
> help you out.
>
> -- Dante
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

The Zend Framework documentation has some notes regarding of
autoloading of resources.

http://framework.zend.com/manual/en/learning.autoloading.resources.html

You may find some mileage there.



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Path question

2011-03-29 Thread D. Dante Lorenso

On 3/28/11 8:18 PM, Jack wrote:

Hello All,
Is there a smarter way to do includes by setting up a path or something
where I don't have to include /home/domain.com/includes/include_file.php
Apparently my path is as shown above,  but I would prefer to just put in
/includes/include_file.php


I wrote about this a long time ago ... perhaps it might help:

http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/

Talks about putting your functions into classes and using the autoloader 
to avoid putting include statements in your code.


Might not help if you are loading content which is not just PHP 
functions/code, but if you haven't "evolved" this far yet, the read 
might help you out.


-- Dante

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Path question

2011-03-28 Thread Paul M Foster
On Mon, Mar 28, 2011 at 09:18:39PM -0400, Jack wrote:

> Hello All,
> 
>  
> 
> Is there a smarter way to do includes by setting up a path or something
> where I don't have to include /home/domain.com/includes/include_file.php
> 
> Apparently my path is as shown above,  but I would prefer to just put in
> /includes/include_file.php
> 

As a first action, in whatever file you first include or call, do the
following:

$site_path = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
define ('SITE_PATH', $site_path);

Next, create a function like:

function include_path($filename)
{
$str = SITE_PATH . 'include' . DIRECTORY_SEPARATOR . $filename;
return $str;
}

Now, when you want to include a file, do

include(include_path('something.php'));

In my projects, I have a variety of directories, like libraries, views,
models, etc. So the function I use has a second parameter:

include(fullpath('model', 'pizza.php'));
include(fullpath('include', 'gesundheit.php'));

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Path question

2011-03-28 Thread Jack
Hello All,

 

Is there a smarter way to do includes by setting up a path or something
where I don't have to include /home/domain.com/includes/include_file.php

Apparently my path is as shown above,  but I would prefer to just put in
/includes/include_file.php

 

 

Thanks!

Jack