PHP going mad.. PLEASE HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

PHP going mad.. PLEASE HELP!

Post 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?!?!
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post 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 ;)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post 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 ;)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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";
Post Reply