Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,543
305
Nowheresville
Code:
<?php
	if(!defined('USR'))
		return;
		
	if($_REQUEST['pf1'] != ""){
		$hdl = fopen(HOMEDIR."$usr/".$_REQUEST['pf1'],'w');
		fwrite($hdl, $_REQUEST['pft']);
		fclose($hdl);
		echo "WROTE FILE";
	}
	
	$data = "HELLO WORLD";
	
function gtdr(){

$dir = HOMEDIR.USR;
$dh  = opendir($dir);

    echo "<html><head><title>HTML EDIT</title></head><body>
    	  <form action='desktop.php?a=$eyeapp' method='post'>NAME:<input type='text' name='pf1'>";
echo "<select name='optsel'>";
while (false !== ($filename = readdir($dh))) {
   $files[] = $filename;
   echo "<option value='$filename'>$filename";
}
echo "</select>";
echo "<br>
    	  <input type='submit' name='pfs' value='Save'><input type='submit' name='pfo' value='Open'>
    	  <input type='reset'><br>
    	  <textarea rows='30' cols='86' name='pft'>";
    	  echo $data;
    	  echo "</textarea>
    	  </body></html>";
return "";
}
gtdr();
?>
Ok here is what I'm trying to do. This dynamically updates whatever files are in a directory of your username. HOMEDIR."$usr/" is taken from eyeOS so that I can point to a specific user directory. Here's the problem. I've tried almost everyway I know to load a file into the <textarea> but it won't load using echo $variable; No matter what I've done. the only way, that I've even got remotely close, is by defining the variable right before where it's used but defining it like this.
$data = "INSERT CODE HERE";
echo $data;
That works, but if I define it outside of the function, it won't show up. When I load information from a file into $data, nothing will show in the <textarea> but I can get it to show up in the Window.

Sorry not making too much sense:
I want to load a file into <textarea> using echo $variable that has read data to it, but it won't load the data into <textarea> via echo $variable;
Make sense now? Sorry I know this is kinda hard.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,543
305
Nowheresville
Thanks, it reads one line of the file into the... whatcha ma call it.... Textarea lol. Here's the code I have now:

Code:
<?php
	if(!defined('USR'))
		return;
	global $data;
	global $x;
	$data = "INSERT CODE HERE";
	$x = 0;
	if($_REQUEST['pf1'] != ""){
		$hdl = fopen(HOMEDIR."$usr/".$_REQUEST['pf1'],'w');
		fwrite($hdl, $_REQUEST['pft']);
		fclose($hdl);
		echo "WROTE FILE";
	}
	if(isset($_REQUEST['optsel'])){
		$hdl = fopen(HOMEDIR."$usr/".$_REQUEST['optsel'],'rb');
		global $data;
		 //global $data;
         $data = fgets($hdl, filesize(HOMEDIR."$usr/".$_REQUEST['optsel']));
		fclose($hdl);
	}
	
function gtdr(){

$dir = HOMEDIR.USR;
$dh  = opendir($dir);

    echo "<html><head><title>HTML EDIT</title></head><body>
    	  <form action='desktop.php?a=$eyeapp' method='post' name='oxel'>NAME:<input type='text' name='pf1'>";
echo "<select name='optsel' onchange=''>";
while (false !== ($filename = readdir($dh))) {
   $files[] = $filename;
   echo "<option value='$filename'>$filename";
}
echo "</select>";
echo "<br>
    	  <input type='submit' name='pfs' value='Save'><input type='submit' name='pfo' value='Open'>
    	  <input type='reset'><br>
    	  <textarea rows='30' cols='86' name='pft'>";
    	  global $data;
    	  echo $data;
    	  echo "</textarea>
    	  </body></html>";
return "";
}
gtdr();
?>

EDIT: GOT IT, change fgets to fread and it works perfectly now. Thanks!
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,543
305
Nowheresville
Ok since fixing the code I have another problem!
I'm making this an HTML editor, but it's not working. When I put in like <textarea> to be saved and that what's after puts it self as if the code is using it the </textarea> is taking control in the original document. How can I fix this?
In otherwords when I save a file with </textarea> in it, it's making the original file end and puts whatever else is in the file at the end of the page.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,543
305
Nowheresville
MontyZ said:
I'm not sure what you are describing, but, if you are trying to store the phrase "<textarea>" with your text, and don't want this translated as HTML, then you should use the htmlentities() function in PHP to turn characters like < into <
The person from eyeOS helped me fix it. He told me there was an embedded function in eyeOS called textarea(rtrim($text)) that would fix that problem. So I used that and it fixed it =D it replaces it with code values instead of </textarea> characters (it shows the </textarea>, but it just fixes it so that it doesn't conflict).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.