Problema de ahorro con TinyMCE

I managed to get it to load the right page in the editor, but now I can't figure out why TinyMCE won't save.

I'm pretty sure it has something to do with this:

  $this_page = $_SERVER["PHP_SELF"];
  $query_string = $_SERVER["QUERY_STRING"];
  echo("<form method=\"post\" action=\"$this_page?$query_string\">\n");
  echo("<textarea id=\"page\" name=\"page\" rows=20 cols=60>\n");
  echo(htmlspecialchars($text));
  echo("</textarea>\n");
  echo("<input type=\"submit\" value=\"Save\">\n");
  echo("</form>\n");

Here's the full version of my new script:

<?php
  // Get the page name from the query string
  $page = $_GET["p"] . ".htm";
  if (!$_GET["p"]) {
    echo("<p>Select a page to work with to begin.\n");
    exit;
  }
  if ($_POST["p"]) {
    $handle = fopen("../includes/$page", "w");
    fwrite($handle, $_POST["p"]);
    fclose($handle);
    echo($_POST["p"]); // OR include("../includes/$page");
    exit;
  }
  if (file_exists("../includes/$page")) {
    $FILE = fopen("../includes/$page", "rt");
    while (!feof($FILE)) {
    $text .= fgets($FILE);
  }
  fclose($FILE);
  } else {
    echo("<h1>New Page: $page</h1>\n");
    $text = "<p></p>";
  }
  echo <<< EOM
  <script language="javascript" type="text/javascript"
    src="/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
  <script language="javascript" type="text/javascript">
    tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "center",
    theme_advanced_path_location : "bottom"
    });
  </script>
EOM;
  $this_page = $_SERVER["PHP_SELF"];
  $query_string = $_SERVER["QUERY_STRING"];
  echo("<form method=\"post\" action=\"$this_page?$query_string\">\n");
  echo("<textarea id=\"page\" name=\"page\" rows=20 cols=60>\n");
  echo(htmlspecialchars($text));
  echo("</textarea>\n");
  echo("<input type=\"submit\" value=\"Save\">\n");
  echo("</form>\n");
?>

EDIT: My file permissions where wrong, but now they're correct and the script still isn't working. Any idea whats wrong?

------------------------- below this line is important but old -------------------------

I'm working on my first, extremely simple CMS, just for editing text. It doesn't add pages, allow uploads or anything like that. It just allows a user to edit pages through a back end.

I had this script working, but went to modify it a great deal, and now I'm having issues.

The links are basically set up like this: <a href="index.php?p=home">Edit the home page</a>

When you click that, it should define ../includes/home.htm as the active page (or ../includes/contact.htm,if the link was index.php?p=contact, etc.), then load TinyMCE in to the #editor section, with the active page as what's being edited.

I'm very new to PHP so this is pretty confusing to me. I followed Un tutorial to get this set up initially, and now I'm trying to make it work how I want it to.

The problem is basically that I don't know what to change in the PHP to make this load correctly.

preguntado el 27 de agosto de 11 a las 15:08

2 Respuestas

I figured it out! This section:

if ($_POST["p"]) {
    $handle = fopen("../includes/$page", "w");
    fwrite($handle, $_POST["p"]);
    fclose($handle);
    echo($_POST["p"]); // OR include("../includes/$page");
    exit;
  }
  if (file_exists("../includes/$page")) {
    $FILE = fopen("../includes/$page", "rt");
    while (!feof($FILE)) {
    $text .= fgets($FILE);
  }
  fclose($FILE);
  } else {
    echo("<h1>New Page: $page</h1>\n");
    $text = "<p></p>";
  }

Necesitaba tener if ($_POST["page"]) en lugar de ["p"]. When I went and changed how the pages where named, I didn't realize the form also had the name of "page".

Respondido 27 ago 11, 20:08

Cambiar

if ($_POST['page']) {

a

 if ($_GET['page']) {

Respondido 27 ago 11, 19:08

That did nothing for me...Figured out my initial question, but now it's won't save for some reason. - JacobTheDev

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.