Page 1 of 1

Help creating with fopen/fwrite

Posted: Sun May 03, 2009 8:42 pm
by manRay
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

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>
 
Here is the php

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!";
?>
 

Re: Help creating with fopen/fwrite

Posted: Sun May 03, 2009 10:32 pm
by manRay
OK!, I must have fixed something, because it is saving to my server. But, it doesn't save the filename, or contents. How is this possible, and what can I do?

Re: Help creating with fopen/fwrite

Posted: Mon May 04, 2009 7:32 am
by manRay
I got it to work, saving as .txt. The problem was I was trying to get the textarea by using $_POST['document'], when it should have been $_POST['file'], Minor error. But while I still have this thread up, how can I save the file as .doc or rtf. Is there special encoding?

Re: Help creating with fopen/fwrite

Posted: Mon May 04, 2009 11:40 pm
by manRay
Is this previous response for something else. I don't see how it relates.

Re: Help creating with fopen/fwrite

Posted: Tue May 05, 2009 1:19 am
by manRay
My initial header was to make sure that the user is loged-in, for extra security purposes.
OK, I got the desired results. Does anybody know how I can save the file other than .txt, possibly to .doc?