rambothefirst Posted February 10, 2014 Share Posted February 10, 2014 Hello all, Really need help with this I have been working on it for a few days, but no luck getting it to work. I am trying to get the file from the server location and place it into a text-box with an editor installed. My first php $file shows the location I need if I echo it, but when I place it all together and try to use js to echo $string its not displaying the text from the file. <?php$f = $_SERVER['DOCUMENT_ROOT'] . "/files/<?php echo safeOutputToScreen($file->localFilePath, null, 55); ?>";$contents = file($f);$string = implode($contents);echo $string;?> <form><textarea id="editor1" name="editor1"></textarea></form><script>CKEDITOR.replace( 'editor1' );</script><script>document.getElementById('editor1').defaultValue="<?php echo $string ?>";</script></div></div></div></body><? include('_footer.php'); ?><?php end() ?> Link to comment Share on other sites More sharing options...
Mudsaf Posted February 10, 2014 Share Posted February 10, 2014 [*]<script>document.getElementById('editor1').defaultValue="<?php echo $string ?>";</script> echo is missing ; <?php echo $string; ?> Link to comment Share on other sites More sharing options...
rambothefirst Posted February 10, 2014 Author Share Posted February 10, 2014 <script>document.getElementById('editor1').defaultValue="<?php echo $string ?>";</script> echo is missing ; <?php echo $string; ?> Sorry my fault it don't work with ; it is just not there because I was copy & pasting. I have tried echo in many different ways. I can also get it to output in the textbox, /files/<?php echo safeOutputToScreen($file->localFilePath, null, 55); ?> it just don’t seem to notice the php and place it as a string. Link to comment Share on other sites More sharing options...
Ingolme Posted February 10, 2014 Share Posted February 10, 2014 This line is a problem because you're already inside a <?php ?> block: $f = $_SERVER['DOCUMENT_ROOT'] . "/files/<?php echo safeOutputToScreen($file->localFilePath, null, 55); ?>"; Substitute it with $f = $_SERVER['DOCUMENT_ROOT'] . "/files/" . safeOutputToScreen($file->localFilePath, null, 55); It might not be the only problem, but it's best to start with the most obvious thing to fix. Link to comment Share on other sites More sharing options...
rambothefirst Posted February 10, 2014 Author Share Posted February 10, 2014 This line is a problem because you're already inside a <?php ?> block: $f = $_SERVER['DOCUMENT_ROOT'] . "/files/<?php echo safeOutputToScreen($file->localFilePath, null, 55); ?>"; Substitute it with $f = $_SERVER['DOCUMENT_ROOT'] . "/files/" . safeOutputToScreen($file->localFilePath, null, 55); It might not be the only problem, but it's best to start with the most obvious thing to fix. Thanks Foxy Mod I have it working now. Is it possible with PHP to open the text file and edit it in textbox and auto save in the same text file.? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 10, 2014 Share Posted February 10, 2014 PHP can read and write files. One way is to use file_get_contents to read a file, and file_put_contents to write to a file. Link to comment Share on other sites More sharing options...
rambothefirst Posted February 11, 2014 Author Share Posted February 11, 2014 PHP can read and write files. One way is to use file_get_contents to read a file, and file_put_contents to write to a file. Is there a better way to open the file and display the text other then the way I am opening text from the code in my first post.? Link to comment Share on other sites More sharing options...
Ingolme Posted February 11, 2014 Share Posted February 11, 2014 Yes, the file_get_contents() function as mentioned just before. It saves you the step of using implode() Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now