Solved

php5: how do i read file from parent directory

Posted on 2011-09-19
2
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 500 total points
ID: 36563814
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
ID: 36568485
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 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