This repository has been archived on 2020-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
paste-manager/htdocs/save.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2012-01-18 23:23:08 +00:00
<?php
require_once("../common.php");
if (!empty($_POST["content"]))
{
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->formatOutput = true;
$xml_paste = $xml->createElement("paste");
2012-01-18 23:23:36 +00:00
$xml_paste->appendChild(
$xml->createElement("title", $_POST["title"]));
$xml_paste->appendChild(
$xml->createElement("author", $_POST["author"]));
$xml_paste->appendChild(
$xml->createElement("language", $_POST["lang"]));
$xml_paste->appendChild(
$xml->createElement("date", time()));
$xml_paste->appendChild(
$xml->createElement("ip", $_SERVER["REMOTE_ADDR"]));
$xml_paste->appendChild(
$xml->createElement("content", $_POST["content"]));
if (!empty($_POST["ref"]))
$xml_paste->appendChild(
$xml->createElement("ref", $_POST["ref"]));
$hash = base64_encode(md5($_POST["content"], true));
$xml_paste->appendChild(
$xml->createElement("hash", $hash));
2012-01-18 23:23:08 +00:00
$xml->appendChild($xml_paste);
2012-01-18 23:23:36 +00:00
//Save the paste
$filename = substr(
str_replace("+", "",
str_replace("/", "",
$hash)), 0, NB_CHAR);
if ($xml->save(DESTINATION . "/" . $filename . ".xml"))
{
//Redirect the user to is paste
header("Location: /?".$filename);
exit;
}
else
die ("Sorry, an error occured while saving the file. Please try again later.");
2012-01-18 23:23:08 +00:00
}
header("Location: /");
?>