I am attempting to run the following code upon form submission to make a new directory, copy an html document the new directory, rename the html document, and save an xml with data from the html form to the directed we created. None of this is happening, but I'm not getting any errors. Any help would be greatly appreciated as I've spent hours troubleshooting this by now, and I still can't see anything wrong.
Here is the PHP script(sorry for the poor formatting, it just won't paste in cleanly):
<?php
if(isset($_POST['submit'])) {
error_reporting(1);
ini_set('display_errors', 'On');
$name = $_POST["name"];
$address = $_POST["address"];
$photo = $_POST['photo'];
mkdir("/kunden/homepages/9/d773272021/htdocs/articles/$name", 0755);
chdir("/kunden/homepages/9/d773272021/htdocs/articles/$name");
copy("/kunden/homepages/9/d773272021/htdocs/input.html", "/kunden/homepages/9/d773272021/htdocs/articles/$name");
rename("/kunden/homepages/9/d773272021/htdocs/articles/$name/input.html", "/kunden/homepages/9/d773272021/htdocs/articles/$name/$name . '.html'");
//XML Data In Documents
$xmlString = "<?xml version='1.0' encoding='UTF-8'?>
<name>$name</name>
<address>$address</address>
<photo>$photo</photo>
";
//The above
$dom = new DOMDocument;
$dom->preserveWhiteSpace = TRUE;
$dom->loadXML($xmlString);
$dom->save("/kunden/homepages/9/d773272021/htdocs/articles/$name" . '.xml');
}
?>
Here is the code for the HTML form(it is working and running the PHP script, but I figure I might as well include it just in case):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Article Creation Wizard (Beta)</title>
</head>
<body>
<form method="post" action="output.php">
Name: <input type="text" name="name"><br>
Address: <input type="text" name="address" /><br>
Photo: <input type="file" name="photo" /><br>
<input type="submit">
</form>
</body>
</html>
Thanks in advance.
EDIT: It works! Kind of... Here's my new script:
<?php
if(isset($_POST)) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$name = $_POST["name"];
$address = $_POST["address"];
$photo = $_POST['photo'];
mkdir("articles/$name", 0755, true);
copy('/homepages/9/d773272021/htdocs/input.html', "/homepages/9/d773272021/htdocs/articles/$name/");
rename("/homepages/9/d773272021/htdocs/articles/$name/input.html", "/homepages/9/d773272021/htdocs/articles/$name/$name.html");
//XML Data In Documents
$xmlString = "<?xml version='1.0' encoding='UTF-8'?>
<name>$name</name>
<address>$address</address>
<photo>$photo</photo>
";
//The above
$dom = new DOMDocument;
$dom->preserveWhiteSpace = TRUE;
$dom->loadXML($xmlString);
$dom->save("articles/$name.xml");
}
?>
The directory and XML file get created, which is great. However, the HTML doesn't get copied and therefore does no get named to its new name.
Here are the errors I'm getting, any help is appreciated:
Warning: copy(): The second argument to copy() function cannot be a directory in /homepages/9/d773272021/htdocs/output.php on line 10
Warning: rename(/homepages/9/d773272021/htdocs/articles/cancer/input.html,/homepages/9/d773272021/htdocs/articles/cancer/cancer.html): No such file or directory in /homepages/9/d773272021/htdocs/output.php on line 11
Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 3 in /homepages/9/d773272021/htdocs/output.php on line 21