Solved

php5: how do i read file from parent directory

Posted on 2011-09-19
2
313 Views
Last Modified: 2012-05-12
hello all,

i have a zend project with followed structure:

Projectname/application/configs/config.ini

Projectname/public/mytest/test.phtml

in config.ini i have an entry: username = abc

the question is: i would write some codes in test.phtml to check if config.ini exist, if it exist, i would like to get the value of username from this file. any suggestion?

thanks,
wantime
0
Comment
Question by:wantime
2 Comments
 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 500 total points
Comment Utility
I assume you are trying to find the file instead of asking about how to do read and write operations in PHP.

Two approaches since it doesn't appear that you are trying to get above the document root.

First is to use a relative path.  Say you are in the folder /Foo/Bar/Bletch and you want to read a file in /Foo/etc called config.ini.  You would open "../../etc/config.ini"

The second works if your server is a *nix operating system and you have shell access.  Simply create a symbolic link from the current folder to the file.

$ ln -s  ../../etc/config.ini  config.ini

.. means the parent folder.
0
 

Author Comment

by:wantime
Comment Utility
thanks.

actually i also would like to read the file.  the link followed helps.

http://devilsworkshop.org/parsing-ini-files-using-php/
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now