zero-perfoliate
zero-perfoliate

Author Topic: fwrite() writes all of my chars as being lietral  (Read 703 times)

Ian

  • Guest
fwrite() writes all of my chars as being lietral
« on: January 12, 2008, 10:47:12 AM »
I am currently in the process of making a file manager. For it, people need to be able to edit files without using FTP, so I decided to make a quick file editor. I have all of the scripts working, but I can't get save.php to write exactly what it reads rather then what it sees. For example:

If I save this:

Code: [Select]
<?php
// include
include('FileIcon.php');

// get the file
$file = new FileIcon('example.txt');

// print the icon plus some data
echo $file -> displayIcon() . '  ' .  $file -> getName() . ' - ' $file -> getSize() . '<br />';

// set the icon url
$file -> setIconUrl('icons/');


// get second file

// print the icon plus some data
echo $file -> displayIcon() . '  ' .  $file -> getName() . ' - \ . $file -> getSize() . '<br />;

?>

I get this:

Code: [Select]
<?php
// include
include(FileIcon.php);

// get the file
$file = new FileIcon(example.txt);

// print the icon plus some data
echo $file -> displayIcon() .    .  $file -> getName() .  -  . $file -> getSize() . <br />;

// set the icon url
$file -> setIconUrl(icons/);


// get second file

// print the icon plus some data
echo $file -> displayIcon() .    .  $file -> getName() .  -  . $file -> getSize() . <br />;

?>

save.php:

Code: [Select]
<?php
$fName $_POST["ffile"]; // edit.php
$fCon $_POST["fCon"]; // edit.php
unlink($fName); // I was going to use file_put_contents, but my host is a little behind.
$fh fopen($fName"x+");
$con fwrite($fh$fCon);
fclose($fh);
?>

open.php:

Code: [Select]
// root file

<link rel="stylesheet" href="/css/style.css" type="text/css">

<div id="open">
<form action="edit.php" method=POST>
<center><small>Please type the file name and dir you would like to open.</small></center><br>
<input type=text name=file><br><br>
<div id=button>
<input type=submit value=open>
</div>
</div>
</form>

edit.php:

Code: [Select]
<?php

$fName $_POST["file"]; // open.php

$con file_get_contents ($fName); // reads the file

?>



<link rel="stylesheet" href="/css/style.css" type="text/css">

<center>

<div id="text">

<form action="save.php" method=POST>
<textarea cols="100" rows="25" name=fCon><? echo "$con"; ?></textarea><br><br>
<center>
<? echo "<input type=text value=$fName name=ffile>"; ?>&nbsp;
<input type=submit value=Save>
</center>
</form>
</div>
</center>

I get no error, it just incorrectly writes things.
« Last Edit: January 12, 2008, 10:50:06 AM by Ian »

 

zero-perfoliate