hello guys..I dont know whether this is right place to post this question. I recently installed LAMP on my ubuntu 10.10 (which is fine) and tried to write a simple php program which writes hello world in it. Then I placed this file in /var/www and using firefox ran the code. Here is what it looks like
<?php
$file_name = "home/muze/Example.txt"; //also tried [i]$file_name = "Example.txt";[/i] but in vain
$text = "Muzammil";
$file = fopen($file_name, "w") or die('Unable to open file');
fwrite($file, $text) or die('Unable to write text');
$contents = file_get_contents($file) or die('Unable to get contents');
echo $contents;
fclose($file);
?>
But this shows error ..."Unable to open file". Whats the problem with code or any configuration that I am missing.
As Vladsun pointed out, the "home" directory is normally in the file system's root directory, not subordinate to the web server's root directory, requiring you to precede the path with a "/". That's no doubt your problem, but I wanted to point out that you would have a lot more help in diagnosing the problem if you include the mysql_error() message in your "die" statements, like this:
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.