Can't get_file_contents?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Severeon
    New Member
    • Feb 2007
    • 1

    Can't get_file_contents?

    Ok, I am a newb to PHP, but I have a good backing in C++ and Java so I have been able to eek out what I need.

    I was going though a 'mambo' conversion of a web plug in for Smart launch, a cafe' administration program.

    Here is my code:

    Code:
     $filename = 'data.dat';
     $postvars = unserialize(file_get_contents($filename));
     
     $i = 0;
     
     for($i = 0; $i <= $postvars['ComputerCount']; $i++)
     {
      switch($postvars['Computer' . $i . '_State'])
      {
        case '0':
         $statustext = "Unavailable / Off";
         break;
        case '1':
         $statustext = "Available for use!";
         break;
        case '2':
         $statustext = "Unavailable / In Use";
         break; 
      }
     
      switch($postvars['Computer' . $i . '_ConsoleType'])
       {
        case '0':
     ?>
     	<div style="position:absolute;top:<? echo $postvars['Computer' . $i . '_X']; ?>px;left:<? echo  $postvars['Computer' . $i . '_Y']; ?>px;width:32px;height:32px;" onmouseover="return escape('<b>Computer #<? echo $i ?><br>Status:</b> <? echo $statustext ?>')">
     		<img src="images/pc_<? echo $postvars['Computer' . $i . '_State']; ?>.png" alt="Computer #<? echo $i ?>">
     	</div>
     <?
         break;
        case '1':
     ?>
     	<div style="position:absolute;top:<? echo $postvars['Computer' . $i . '_X']; ?>px;left:<? echo  $postvars['Computer' . $i . '_Y']; ?>px;width:32px;height:32px;" onmouseover="return escape('<b>XBOX<br>Status:</b> <? echo $statustext ?>')">
     		<img src="images/xbox_<? echo  $postvars['Computer' . $i . '_State']; ?>.png" alt="xbox"><br>
     	</div>
     <?
         break;
        case '2':
     ?>
     	<div style="position:absolute;top:<? echo $postvars['Computer' . $i . '_X']; ?>px;left:<? echo  $postvars['Computer' . $i . '_Y']; ?>px;width:32px;height:32px;" onmouseover="return escape('<b>PS2<br>Status:</b> <? echo $statustext ?>')">
     		<img src="images/ps2_<? echo  $postvars['Computer' . $i . '_State']; ?>.png" alt="ps2"><br>
     	</div>
     <?
         break;
       }
     }
     
     ?>
     <script language="JavaScript" type="text/javascript" src="wz_tooltip.js"></script>

    I keep getting an error though mambo of this "Warning: file_get_conten ts(data.dat): failed to open stream: No such file or directory in E:\inetpub\vhos ts\pixelated.co m\subdomains\XG N\httpdocs\CMS\ modules\mod_com puterStatus.php on line 22 "

    The file "data.dat" is in the correct directory, and my Smart Launch server has and does update to it correctly; but the code still can't see it. What am I doing wrong?
  • TheMadMidget
    New Member
    • Oct 2006
    • 98

    #2
    check permissions

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Welcome to The Scripts.
      Two things may be wrong: permissions, and working directory.
      PHP scripts run from the permissions of the web-server. If this is a *nix machine, it is probably nobody, www, or apache. If this user does not have the permissions to access this file, then the call will fail.
      Depending on the exact configuration of the web-server, not specifying a path could land you in any number of directories. If you are running in Windows you may even end up at C:\. Try specifying the entire path to see if it will work then.

      Comment

      • steven
        New Member
        • Sep 2006
        • 143

        #4
        Make sure data.dat is in the same directory as your PHP script, or change the $filename variable to indicate it's location.

        Also confirm the webserver has read permissions on the file in question.

        Comment

        Working...