Jump to content

Creating a .php file editor issues...


the_magic_zebra

Recommended Posts

Hello, I have a small bug I'm attempting to fix but haven't come to any working solutions yet.

 

I'm working on a file editor box, that allows me to view, edit, and save the contents of a .php file. First, I wrote a script that detected every file in a certain folder, then displays the file in a list format on the screen with links for each file to execute an AJAX function. When you click on one of the links, the AJAX function is triggered, and the contents of the file name that you clicked on immediately show up in a textarea box on the screen. From here, you can edit and save the contents.

 

In a nutshell, I'm attempting to code up my own file editor in PHP so that I don't have to rely on Cpanel to make changes to my PHP pages. The issue with this is, when I get the file contents and display it, everything seems to be working fine. I can even make changes, however once the changes are saved and the file is updated with the new contents within the textarea, any time I hit return to move to a new line, the new lines get wiped out.

 

(When I populate the textarea with source code, to keep it from running I use htmlspecialchars() so that it displays all the source code unparsed.)

 

For example:

 

If I clicked on sample.php, the textarea would show the source code for that page:

 

<?php

 

echo "this is a sample php page";

 

?>

 

Then I could make these changes and click save:

 

<?php

 

echo "i changed this part of the file";

 

?>

 

After saving and clicking on the sample.php page to view the recently updated source code, the textarea shows this:

 

<?phpecho "i changed this part of the file";?>

 

As you can see, any time I hit return to begin code on a new line, the new lines get removed.

 

I'm not sure how to put those lines back in to the source code. Any ideas?

 

Link to comment
Share on other sites

Seems a little long winded, if you dislike using cPanel, why not use an FTP client on your desktop togehter with notepad or another editor programme like Dreamweaver if you have it.

 

Yes, the easy route would be to simply abandon the idea of creating my own file editor, however I learn nothing by doing it that way.

 

In regards to cPanel, I do not "dislike" it, I just want to be able to do everything from my own administrator area on the site rather than relying on my custom admin area to edit one part of the site and cPanel for another.

Link to comment
Share on other sites

What do you mean? Nothing will ever parse within a <textarea> htmlspecialchars is pointless.

<textarea><b>?</b><a href="foo" onClick="alert('bar');">baz<a/></textarea>

 

See? Nothing will run if you put that in your browser. Further:

 

You should use fread/fwrite( with the w attribute, to replace the file ), it shouldn't be a hard task. Further, adding AJAX into the solution will just cause security holes in the end, if you do not know what you are completely doing.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.