FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[PHP doubt]Knowing the directory location of PHP file





rohan2kool
Actually, I want to know the directory in which the PHP file being processed is located. For ex. if there is an index.php in c:/program files/apache group/apache2/htdocs/mysite/index.php ... then in the index.php file, I want a variable, say $myvar which should be equal to "c:/program files/apache group/apache2/htdocs/mysite" and if in Linux, then something like, "/usr/local/apache-1.3.33.23/htdocs/mysite" . Please help.
Stubru Freak
rohan2kool wrote:
Actually, I want to know the directory in which the PHP file being processed is located. For ex. if there is an index.php in c:/program files/apache group/apache2/htdocs/mysite/index.php ... then in the index.php file, I want a variable, say $myvar which should be equal to "c:/program files/apache group/apache2/htdocs/mysite" and if in Linux, then something like, "/usr/local/apache-1.3.33.23/htdocs/mysite" . Please help.


Isn't that $_SERVER['SCRIPT_FILENAME'] ?
comp615
If your trying to use it in a link or something you can just use ./ for current dir or ../ for parent dir.
rohan2kool
Actually i want it for an upload script. I want to get the current folder. say '$x'. Then, the file recieved is copied to $x/files. I am testing it on a windows server, but when i upload it, it might be a linux server, rather it is a linux server.
dandelion
You can get the current work directory using the getcwd() function.
Then use it with the move_uploaded_file() function.
sonam
If I good understand your problem you are looking root function.

$index = $_SERVER['DOCUMENT_ROOT'] . "/index.php";

or if you would like to catch some other folder:

$other = $_SERVER['DOCUMENT_ROOT'] . "/someotherFolder/some.php";
rohan2kool
Actually, comp615's solution worked exactly fine, even while uploading. I just copied the $_FILES['file']['tmp_name'] to ./files/$_FILES['file']['name']... and presto it worked in both, Windows and Linux. Thanks everybody.
Related topics
File upload with PHP, Build an upload database for your site
Installing a SMF based forum
Inserting data to MYSQL with a PHP script
Java tutorials
PHP Test File
PHP homepage recreation problem
Directory copying is not currently supported (*SOLVED*).
[PHP] Executing a local file
php - access root directory
Script for Upload Form
Is Frih PHP supported
PHP Read File Help needed.
Flat file-based, MySQL-based counter
Making some things vars
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.