NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > Webmaster Tutorials
Reload this Page PHP File Editor

Webmaster Tutorials Instructional webmaster-related how-to's and tutorials.

Advanced Search
0 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 07-31-2006, 01:39 PM THREAD STARTER               #1 (permalink)
NamePros Member
 
bquast's Avatar
Join Date: Nov 2005
Location: Hardisty, Alberta Canada
Posts: 179
bquast will become famous soon enough
 



PHP File Editor


Well, I had always wanted to learn how to create my own file editor so that I could edit my ad files on my websites, and well I have accomplished just that, and I will be teaching you how to do just that with this php tutorial.

Step 1:
Open up whatever program you use to create webpages with, and start out with a simple html page.

PHP Code:
<html>
<head>
<title>File Editor</title>
</head>

<body>
<form action="edit.php" method="post" name="edit">
<h1>Password</h1>
<p><input name="password" type="password" id="password" value=""/></p>
<p><textarea name="edit" cols="70" rows="20">
<?php
$handle 
fopen('file.php''r');
$file file_get_contents('file.php');

echo (
$file);

fclose($handle);
?>
</textarea></p>
<p><input name="submit" type="submit" value="Edit Ads File"/></p>
</form>
</body>
</html>
Now let me explain the php code in this tutorial.

PHP Code:
$handle fopen('file.php''r'); //opens the file you want for reading 
PHP Code:
$file file_get_contents('file.php'); //gets the contents of the file you want to open 
PHP Code:
echo ($file); //self explanatory, but it echoes the files contents into the textarea 
PHP Code:
fclose($handle); //closes the open file 
Now save this file as editor.php, as you will notice there is a password field thrown in there as well. We don't want any visitors editing the file do we? To prevent the visitors we have password protected the editor.php file from access unless the individual can guess your password.

Step 2:
Now we will create the edit.php file, the code is below and an explenation will follow.

PHP Code:
<?php
$filename 
'file.php';
$somecontent stripslashes($edit);
$password "yourpassword";  //checks the editor.php files password to see if it matches if not it goes to the else statement.
if($_POST['password']==$password)
{
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    
// In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    
if (!$handle fopen($filename'w+')) {
         echo 
"Cannot open file ($filename)";
         exit;
    }

    
// Write $somecontent to our opened file.
    
if (fwrite($handle$somecontent) === FALSE) {
????: NamePros.com http://www.namepros.com/webmaster-tutorials/222836-php-file-editor.html
        echo 
"Cannot write to file ($filename)";
        exit;
    }
    
    echo 
"Success, wrote ($somecontent) to file ($filename)";
????: NamePros.com http://www.namepros.com/showthread.php?t=222836
    
    
fclose($handle);

} else {
    echo 
"The file $filename is not writable";
}
}else {
    echo (
"Wrong Password Entered");
}
?>
Now thats alot of php code. it isn't has hard as it looks the explenation has been included with the code, as I am currently feeling lazy and it was 2:00 AM when I was writing this tutorial.

That is all you need, an optional step if you are hosted on a linux server whould be to chmod the file to 777, so that you can actually edit it.

Hopefully this helps some people out there create a file editor, I might come back to this tutorial at a Later date but for now this is as far as I have gotten.
bquast is offline  
Old 08-01-2006, 07:51 AM   #2 (permalink)
NamePros Member
Join Date: May 2006
Posts: 133
spacetrain will become famous soon enoughspacetrain will become famous soon enough
 



Thanks for the info, Rep Added
spacetrain is offline  
Old 08-01-2006, 10:01 AM   #3 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 173
brianmn is on a distinguished road
 



Thanks for the great tutorial...

I'll definately be referencing this tutorial for use on my site.
brianmn is offline  
Old 08-01-2006, 01:16 PM THREAD STARTER               #4 (permalink)
NamePros Member
 
bquast's Avatar
Join Date: Nov 2005
Location: Hardisty, Alberta Canada
Posts: 179
bquast will become famous soon enough
 



no problem guys, I might have some more up sometime here soon.
__________________
Photoshop-ed Your source for everything photoshop
FH4YOU Free file hosting for you
ThemezFree Your ultimate source for free proxy templates
bquast is offline  
Old 08-21-2006, 02:40 AM   #5 (permalink)
NamePros Regular
 
fleshas's Avatar
Join Date: Mar 2005
Location: Lithuania
Posts: 677
fleshas is a jewel in the roughfleshas is a jewel in the roughfleshas is a jewel in the rough
 


Cystic Fibrosis
thanks.. rep added
fleshas is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 12:59 AM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger