Ok, so here’s the problem. I’ve got a page with which I can edit the code of other pages. It’s not exactly user-friendly, and that’s the way I like it. But, I can’t get it to create files correctly. Code is below, followed by the errors I’m recieving.
[code=php]<?php
if ($_POST[‘filecontents’] != “”)
{
if (file_exists($_POST[‘filename’]) == FALSE)
{
touch($_POST[‘filename’]);
}
$handle = fopen($_POST[‘filename’], “w+”);
fwrite($handle, $_POST[‘filecontents’]);
fclose($handle);
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html>
<head>
<title>Create and or Edit Files</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
</head>
<body style=”text-align: center;”>
<?php
if ($_POST[‘filecontents’] != “”)
{
echo “You just saved a file!!! WHOOPIE!”;
}
?>
<form action=”filechanger.php” method=”post”><textarea rows=”20″ cols=”125″ name=”filecontents”><?php
if ($_GET[‘filename’] != “”)
{
$filename = $_GET[‘filename’];
$filecontents = file_get_contents($_GET[‘filename’]);
$safefilecontents = htmlspecialchars($filecontents);
echo $safefilecontents;
}
if ($_POST[‘filename’] != “”)
{
$filename = $_POST[‘filename’];
$filecontents = file_get_contents($_POST[‘filename’]);
$safefilecontents = htmlspecialchars($filecontents);
echo $safefilecontents;
}
?></textarea><input type=”hidden” value=”<?php echo $filename ?>” name=”filename” />
<?php
if ($filename == “”)
{
echo “n<br />You aren’t opening a file, so put the filename you want to save this text as right here:n<br /><input type=”text” size=”75″ />”;
}
?>
<br /><input type=”submit” value=”Save” /><input type=”reset” value=”Reset” /></form>
</body>
</html>
And that’s getting me this:
[quote=PHP]
Warning: touch() [function.touch]: Utime failed: Permission denied in C:Documents and Settings*
Warning: fwrite(): supplied argument is not a valid stream resource in C:Documents and Settings*
Warning: fclose(): supplied argument is not a valid stream resource in C:Documents and Settings*
I’m confused as to why it won’t work. I have other files in the save directory, creating files, by using fopen in x+ mode. Anyone think they know what I messed up? Thanks!