Help creating with fopen/fwrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Help creating with fopen/fwrite

Post 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!";
?>
 
Last edited by Benjamin on Sun May 03, 2009 9:33 pm, edited 1 time in total.
Reason: Changed code type from text to html, php.
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: Help creating with fopen/fwrite

Post 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?
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: Help creating with fopen/fwrite

Post 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?
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: Help creating with fopen/fwrite

Post by manRay »

Is this previous response for something else. I don't see how it relates.
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: Help creating with fopen/fwrite

Post 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?
Post Reply