Problem with cache in file_exists() function

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
InSion
Forum Newbie
Posts: 11
Joined: Thu Oct 21, 2004 7:20 am

Problem with cache in file_exists() function

Post by InSion »

Hi, I'm looking if some files exists and if they don't, I create them manually (they're flash files). The problem is that after uploading them, they are still being shown as inexistant files... After some headache I found that there could be a cache problem, I tried using clearstatcahce() but probably I'm using it worng :?: . Here is the relevant part of the code:

Code: Select all

<?php
    #Show the result in a table
      	while ($row=mysql_fetch_array($result)) {
		    if ($row["IDalojamiento"] < 10) { $numero = '00'.$row["IDalojamiento"]; }
		    elseif ($row["IDalojamiento"] < 100) { $numero = '0'.$row["IDalojamiento"]; }
		    else { $numero = $row["IDalojamiento"]; }
	      if (!(file_exists($root.'alojamientos/pel/alo'.$numero.'.swf'))) {
			echo '<tr>';
        	echo '<td align="center" class="labelcell">';if ($row["alta"] == 1) { echo '*'; }
			echo '</td>';
			echo '<td align="center" class="labelcell">'.$row["IDalojamiento"].'</td>';
			echo '<td align="left" class="labelcell">'.$row["nombre"].'</td>';
			echo '<td align="left" class="labelcell">'.$row["direccion"].'</td>';
			echo '<td align="center" class="fieldcell"><a href="contenido.php?sistema=1&seccion=modificacion&id='.$row["IDalojamiento"].'">Modificar</a></td>';
			echo '</tr>';
		  }
		  #Clear cache
		  clearstatcache();
      	}
?>
This generates a table (start and ends are out) this way:
| * | ID | name | address | Modify button |

Any help would be appreciated. Thank you very much
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

move clearstatcache before file_exist. this way you will always have fresh data.
InSion
Forum Newbie
Posts: 11
Joined: Thu Oct 21, 2004 7:20 am

Post by InSion »

That was what I did at once then I moved It after... anyway I tried again and the problem persists...
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

why dont you try something like this:

Code: Select all

$file = $root.'alojamientos/pel/alo'.$numero.'.swf';


echo $file;

if (file_exists($file)) {
    echo 'yes';
} else {
    echo 'no';
}

before trying to see if it exists. that way YOU can SEE if it really exists or not.

the problem is likely related to relative file paths, im guessing.


feyd | use the

Code: Select all

tags![/color]
InSion
Forum Newbie
Posts: 11
Joined: Thu Oct 21, 2004 7:20 am

Solved

Post by InSion »

:lol: Thank you, it was a stupid problem I discovered when printing $file... $root was pointing to c:/InetPub/wwwroot/ and it should point to c:/InetPub/wwwroot1/... As the site is twice, It correctly detected the file was missing, but in the incorrect site. Thank you very much :oops:.
Post Reply