Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with file_exists - Please help!

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
0
0
US
I have
Code:
if (file_exists("c:/appl/data/piechart.txt"))
{
 $fdata = file("c:/appl/data/piechart.txt");
 $size = sizeof($fdata);
 for($i = 0; $i < sizeof($fdata); $i++){
  if ($i == 1) {	// Data Headings
    list($hdept,$hfreight,$houtlay,$hhandling,$hpos,$hshipments)=split("~",$fdata[$i]);
  } elseif ($i == 2) {	// Air
     list($adept,$afreight,$aoutlay,$ahandling,$apos,$ashipments)=split("~",$fdata[$i]);
   } elseif ($i == 3) {	// Ocean
     list($odept,$ofreight,$ooutlay,$ohandling,$opos,$oshipments)=split("~",$fdata[$i]);
   } elseif ($i == 4) {	// Surface
     list($sdept,$sfreight,$soutlay,$shandling,$spos,$sshipments)=split("~",$fdata[$i]);
   }
}

I have used this kind of code in linux countless times w/out problems. For the first in windows and it does not work. file_exists() is returning FALSE and the file, I can assure, you is there.

Why won't file_exists() find the file?

Thanks
 
Well is this:
c:/appl/data/piechart.txt

on the server running the web browser and PHP, or is it on the client's C drive?

If its on the server, make sure that the user as whch the webserver is running has access to that path and rights to read the path.

If its in the client's C drive, then that's wrong. as PHP cannot interact with the client. So cannot read files from it.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
It is on the server ... I even tried using a directory within root directory of my site

c:\websites\mysite\data

I then used:
Code:
if (file_exists("/data/piechart.txt"))

and

if (file_exists("./data/piechart.txt"))

and

if (file_exists("data/piechart.txt"))
and they all fail. I know that the page I am running is in the root directory as well.

This is beating me inside out ... I have looked at this one line of code all day and still cannot get it to work.

Never had any problems with LINUX using this ...

Thanks,



 
vacunita asks about permissions but you did not respond. Does the permissions under which the webserver is running have access to the directory in which your piechart is stored? and do you have safe_mode turned on?

 

safe_mode = Off

I checked on properties for c:\appl and set Full Control to every user listed ... Only myself and Users ...

Still, no luck!

I'm going to try fopen("file","r") and see what happens ... I do not expect anything different but who knows

What do you think?

OT: How do I check what user is webserver running as? 8-(

 
Reading over the php.net manual for this function, I found

If you are experiencing problems with reading and writing to files and you're using the server module version of PHP, remember to make sure that the files and directories you're using are accessible to the server process.

I am using WAMP5 developing off a Win XP Pro - How then do I make sure this is not the case?

I have the problem no matter where I put the file. I have placed the file within mysite.com root directory, a subdirectory there in and nothing ... problem persists ...

The project I am working on will involve ftp to unix box, get the text file to winidows (where the site runs) and push data to web page.

I never thought I would hit this brick wall ... I can't believe how such a simple thing can rip a whole like this ... this is just driving me crazy (well, combined with a million other things going on all around me).

As usual, your assistance is appreciated!
 
try this script to test things

Code:
$filename = 'test.txt';
$fh = fopen($filename, 'a+');
fwrite($fh, "This is a test \r\n");
fclose($fh);

if (file_exists($filename)){
 echo 'file exists<br/>';
 $fcontent =file_get_contents($filename);
 echo "file contents are :<br/><div style=\"color:red;\">$fcontent</div>";
} else {
 echo "file does not exist";
}
 
No problem .. It created the file and was able to read it!

 
Do you think it would help if the file was named data.txt and not data.txt.txt?

My God, talk about taking things down to basics ... If I were billing a customer for this, I wonder if all the time it took me to figure that the file name was the problem should be billable :)

I am working too many hours - Need to take a couple days off and try to run program: mymind /release; mymind /renew

Thank you guys!
 
the name of the file is not of any consequence. i suspect that you're not addressing the file name correctly (with absolute or relative path)
 
jpadie,

The problem was that I had been looking for data.txt while the actual file name was data.txt.txt.

The error was at source the way they named the file. I am so used to seen files named as [filename.ext] that looking at a windows file named data.txt was perfectly normal.

I decided to rename the file to simply data and BANG!, problem solved.

Like they say, there's rarely ever anything wrong with the program ... now, what you tell it to do ... that is a different story!

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top