Jump to content

Recommended Posts

I'm serializing the array, and all, but it's writing it back to the text file as "Array".

[code]

  $textfile = "filelist.txt";
  if (file_exists($textfile) && is_file($textfile)) {
  $fp = fopen($textfile, "r");
  $file = file_get_contents($textfile, False, NULL);
  $rows = explode("\n", $file);
    if(isset($_POST['checksubmit'])) {
        if(isset($_POST['row']))
          foreach($_POST['row'] as $i)
              unset($rows[$i]);
      serialize($rows);
      $fpw = fopen($textfile, "w");
      flock($fpw, LOCK_EX);
      fwrite($fpw, $rows);
      flock($fpw, LOCK_UN); 
      }
    }
  echo "<form action=\"" . append_sid("admin.php") . "\" method=\"POST\">";
      foreach($rows as $x => $row) {
        if($row == ""){
          continue;
        }
      echo '<input type="checkbox" name="row[]" value="'. $x .'">' . $row . "<br /> ";
      }
  echo "<input type=\"hidden\" name=\"checksubmit\">";
  echo "<br /><input type=\"submit\" value=\"Delete Selected\">";
  echo "</form>";
  }
[/code]

Now, as you can see, I'm using explode() on part of the array, not sure it that could cause part of the problem. Anyway, what is wrong in this code that would be causing the array to keep writing back as Array?
Link to comment
https://forums.phpfreaks.com/topic/15224-array-not-writing-to-file-as-expected/
Share on other sites

i have a feeling that it's because you're not returning the serial to anything.  serialize() doesn't work directly on the variable, it returns the serialized version.  try this:

[code]$serialized_array = serialize($rows);
...
fwrite($fpw, $serialized_array);[/code]

haven't used serialize before, so this is a guess.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.