hi guys, need help, the fopen () command does not run on my program, i don't think what's the problem, please help me

<?php 
$ourFileName = "C:\server\htdocs\samples\php\sample.txt";
$fh = fopen($ourFileName, 'r') or die("Can't open file");
fclose($fh);
?>

hi guys, need help, the fopen () command does not run on my program, i don't think what's the problem, please help me

<?php 
$ourFileName = "C:\server\htdocs\samples\php\sample.txt";
$fh = fopen($ourFileName, 'r') or die("Can't open file");
fclose($fh);
?>

Hi !!!!

Use following code to open the file

<?php

$filename = 'sample.txt';
$path = $_SERVER['DOCUMENT_ROOT'].'/sample/php/'. $filename;

$fh = fopen($path , 'r') or die("Can't open file");
fclose($fh);

?>

Please echo $path if there is twice 'sample' remove 'sample' from the $path.

Thanks :)
Ranjeet

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.