absolute vs relative paths

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andreas_d
Forum Newbie
Posts: 5
Joined: Sun Jun 20, 2004 5:46 pm

absolute vs relative paths

Post by andreas_d »

hi, this is a follow up to a question i posted yesterday. I'm a newbie when it comes to php so this may be very basic i don't know. i have a flash movie sending certain vars to a php script that in turn copies them to a .txt file. the PHP script looks like this

<?php
$value0 = $_POST['value0'];
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
$value3 = $_POST['value3'];
$value4 = $_POST['value4'];
$value5 = $_POST['value5'];
$testvar = "sunset.txt";
$contents = "&value0=".$value0."&value1=".$value1."&value2=".$value2."&value3=".$value3."&value4=".$value4."&value5=".$value5;
$filename = fopen( $testvar, "w");
fwrite($filename, $contents, 10000);
fclose ($filename);
?>

This php script works ok. But i am trying to change line 7 in the script
$testvar = "sunset.txt"; from the relative path to an absolute path
i should mention at this point i am working with on Mac osX and am working locally, not on the internet.
to launch the php script localy i use this in the address bar

'http://myHarddrive.local/~andreas/info/sunset.php'

i thought that the absolute path to the file sunset.txt would be

http://myHarddrive.local/~andreas/info/sunset.txt but when i use this path in line 7 of the php code the script no longer works. Does anyone have any ideas as to what the absolute path should be?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

I don't know if this will work on a Mac but how about this?

Code: Select all

$testvar = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'sunset.txt';
andreas_d
Forum Newbie
Posts: 5
Joined: Sun Jun 20, 2004 5:46 pm

Post by andreas_d »

wow that went completely over my head. is file a parameter i should substitute, if so what file and what is DIRECTORY_SEPARATOR? thanks for the post
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

__FILE__ is the current file it's called in (it's a PHP core constant)

DIRECTORY_SEPERATOR is also a core constant (that I remember) which could contain ':' or ';' or '/' or any number of symbols used by the OS php is running on.
Post Reply