Jump to content

Archived

This topic is now archived and is closed to further replies.

CouchMaster

It just quit working

Recommended Posts

This code was working fine 2 days ago.  It shows a photo with info and a price beneath it.
The photo still shows but the info and price quit showing.  Any ideas what went wrong?

    <?php
    echo "<img class=\"main_img\" src=\"./images4/$_GET[name].jpg\" width=\"575\" height=\"375\" alt=\"$_GET[name]\">";
  echo "</font><p><font color=\"white\"><b>";


$handle = fopen("./images4/$_GET[name].txt", "r");
while (!feof($handle)) {
  $buffer = fgets($handle, 4096);
}
fclose($handle);
$myarray = array(); 
$myarray = explode("|", $buffer);
echo "$myarray[1]<br><br>$myarray[2]<br><br><font color=\"blue\">$myarray[3]</font>";
echo "</b></font></p>";
?>

Share this post


Link to post
Share on other sites
If the code was working previously, and the code hasn't changesd, then the input file has. Check the input file and for debugging purposes, echo the content of $buffer before splitting it inot an array.

Share this post


Link to post
Share on other sites
Tried the suggestion and - nothing.  It's not opening the txt file, which appears normal.  If I echo $handle I get - Resource id #1 - if that means anything - but nothing on $buffer.
Also the txt file is like this - |name|data|price|
One reason I'm asking is because the other day everything stopped working  I realized I was using $name, and when I changed it to $_GET[name] (something about globals) it started working again.  Now something else went haywire and I'm guessing it a similiar problem but I can't find it in my php book.
Suggestions?????????????

Share this post


Link to post
Share on other sites
Is this on your own machine or a shared hosting machine? If it is on a shared hosting machine, contact the support people and ask them if anything changed in the last few days. You may be surprised. It sounds like they upgraded PHP from v4.something to v5.something

When posting code, please surround your code with the [b][nobbc][code][/code][/nobbc][/b] tags. You can edit your post to add them. This will make you code much easier to read.

Here's how I would write your code (this may or may not solve your problem):
[code]  <?php
      echo '<img class="main_img" src="./images4/' . $_GET['name'] . '.jpg" width="575" height="375" alt="' . $_GET['name'] . '">';
      echo '</font><p style="color:white">';  // I am assuming that the background color is not white here...
      $lines = file('./images4/' .$_GET['name'] . '.txt');
      foreach ($lines as $line)
            if (strlen(trim($line)) > 0) $myarray = explode("|", trim($line)));
              echo $myarray[1] . '<br>' . $myarray[2] . '<br><span style="color:blue">' . $myarray[3] . '</span>';
      echo "</p>";
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Ken, your amazing - that actually works, just like it did before!  I will study this carefully, and Thanks a Million.  And I do believe that the two hosting companies that I use are upgrading php - it's just ironic that they are doing the same thing at the same time and it crashed on both on the same day!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.