Page 1 of 1

absolute vs relative paths

Posted: Mon Jun 21, 2004 12:17 pm
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?

Posted: Mon Jun 21, 2004 12:53 pm
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';

Posted: Mon Jun 21, 2004 1:07 pm
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

Posted: Mon Jun 21, 2004 1:12 pm
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.