Help creating with fopen/fwrite
Posted: Sun May 03, 2009 8:42 pm
I am trying to make an online document editor, much like google's own. I need help saving the new content to a new file. But it doesn't save!. I think it doesn't save, because the file doesn't exist initially until now. This is my code so far.
Here is the form
Here is the php
Here is the form
Code: Select all
<form action="savefile.php" method="post">
<p align="left"><input type="text" name="filename" size="30"/></p>
<p align="left"><textarea rows="20" cols="80" name="file">
</textarea></p>
<input type="submit" value="Save" class="btn"/>
</form>
Code: Select all
<?php
session_start();
if (!isset($_SESSION['email'])) {
header("Location: http:../index.html");
}
$file=$_POST['document'];
$filename=$_POST['filename'];
$email = $_SESSION['email'];
$dir = "../users/$email/documents/";
$handle=fopen($dir.$filename,'w');
if(fwrite($handle,$file))
$ok=1;
else
echo "not saved!";
?>