By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,643 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,643 IT Pros & Developers. It's quick & easy.

Can't get_file_contents?

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  $filename = 'data.dat';
  3.  $postvars = unserialize(file_get_contents($filename));
  4.  
  5.  $i = 0;
  6.  
  7.  for($i = 0; $i <= $postvars['ComputerCount']; $i++)
  8.  {
  9.   switch($postvars['Computer' . $i . '_State'])
  10.   {
  11.     case '0':
  12.      $statustext = "Unavailable / Off";
  13.      break;
  14.     case '1':
  15.      $statustext = "Available for use!";
  16.      break;
  17.     case '2':
  18.      $statustext = "Unavailable / In Use";
  19.      break; 
  20.   }
  21.  
  22.   switch($postvars['Computer' . $i . '_ConsoleType'])
  23.    {
  24.     case '0':
  25.  ?>
  26.      <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 ?>')">
  27.          <img src="images/pc_<? echo $postvars['Computer' . $i . '_State']; ?>.png" alt="Computer #<? echo $i ?>">
  28.      </div>
  29.  <?
  30.      break;
  31.     case '1':
  32.  ?>
  33.      <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 ?>')">
  34.          <img src="images/xbox_<? echo  $postvars['Computer' . $i . '_State']; ?>.png" alt="xbox"><br>
  35.      </div>
  36.  <?
  37.      break;
  38.     case '2':
  39.  ?>
  40.      <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 ?>')">
  41.          <img src="images/ps2_<? echo  $postvars['Computer' . $i . '_State']; ?>.png" alt="ps2"><br>
  42.      </div>
  43.  <?
  44.      break;
  45.    }
  46.  }
  47.  
  48.  ?>
  49.  <script language="JavaScript" type="text/javascript" src="wz_tooltip.js"></script>
  50.  
  51.  

I keep getting an error though mambo of this "Warning: file_get_contents(data.dat): failed to open stream: No such file or directory in E:\inetpub\vhosts\pixelated.com\subdomains\XGN\htt pdocs\CMS\modules\mod_computerStatus.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?
Feb 5 '07 #1
Share this Question
Share on Google+
3 Replies


TheMadMidget
P: 98
check permissions
Feb 5 '07 #2

Motoma
Expert 2.5K+
P: 3,235
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.
Feb 5 '07 #3

100+
P: 143
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.
Feb 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.