Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php5: how do i read file from parent directory

Posted on 2011-09-19
2
Medium Priority
?
329 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 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

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