Page 1 of 1

PHP going mad.. PLEASE HELP!

Posted: Fri Aug 16, 2002 4:47 pm
by Gen-ik
Right then..

I have an array of names called
$NAMES
with 5 names in it.

I generate a random number
$NUMBER = rand(0, 4);

I set a variable contain a random name pulled from the array
$randomNAME = $NAMES[$NUMBER];

I then create a variable containing a path to a file
$namePATH="People/$randomNAME/pictures/info.txt";

Now.. when I try to open this file (and it DOES exsist) PHP screams at me saying it DOESN'T exsist!!!

I open the file like this

$openFILE = fopen($namePATH, "r");
$personsINFO = fread($openFILE, filesize($namePATH));
fclose($openFILE);


I'm confused.

Can anyone help with this?!?!

Posted: Fri Aug 16, 2002 9:09 pm
by lc
http://www.php.net/manual/en/function.fopen.php

Go look there.. the r command only opens a file, it does not create one in case it does not exist.

You probably want another ;)

Posted: Fri Aug 16, 2002 9:44 pm
by volka
I think "r" is ok since there is only a call to fread "(and it DOES exsist)"
try something like

Code: Select all

function checkPath($sPath)
{
	$arrPath = split('/', $sPath);
	$sPath = '';
	
	for($i=0; $i!=count($arrPath); $i++)
	{
		$sPath .= $arrPathї$i];
		print($sPath.' ');
		if ( is_dir($sPath) )
			print(" directory\n");
		else if ( is_file($sPath) )
			print(" file\n");
		else
			print(" failed\n");
		$sPath .= '/';
	}
}
to see at which part of the path it begins to complain.
  • string contains really what you expect?
  • current working directory is right?
  • the script has read/change-into permission for the paths?

Posted: Fri Aug 16, 2002 9:51 pm
by lc
LOL volka... it's late and I apparently didn't read it right... I'll stop trying to help people for the remainder of the day ;)

Posted: Fri Aug 16, 2002 9:52 pm
by hob_goblin
could you show us the error?

try changing

Code: Select all

$namePATH="People/$randomNAME/pictures/info.txt";
to

Code: Select all

$namePATH="People/".$randomNAME."/pictures/info.txt";