OK, I cannot see for looking :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LOFer
Forum Newbie
Posts: 2
Joined: Mon Dec 04, 2006 6:48 am

OK, I cannot see for looking :(

Post by LOFer »

Probably something real simple but I could do with some input here.

I have a script that takes form input data and writes it back to ifcfg-eth0 with no problem but, I cannot see (though I confess I am no PHP code-monkey :roll: ) how I can get the file to be written back in unix format.

When I write the file back using the code below and reboot the server, the system cannot read the file and looking at it in Webmin I get a message indicating that the filename has invalid characters!!!???.

However, if I simply vi the file and :set ff=unix, save and quit and then reboot the server, the config file works fine so I am thinkin' it's a file format issue. (The byte size of the file changes if I do the ff thing, it reduces by circa 6 so it's stripping something out)

Code below

Code: Select all

$fn = "/etc/sysconfig/network-scripts/ifcfg-eth0";

//--------------------------------------------------
		// Removes backslashes
		//--------------------------------------------------
			$content = stripslashes($_POST['content']);
		//--------------------------------------------------
		// Removes trailing linespace
		//--------------------------------------------------
			$content = trim($content); 
		//--------------------------------------------------
		//Open the file for writing, zero content the file
		//--------------------------------------------------
			$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
		//--------------------------------------------------
		// Then write the new sanitized content
		//--------------------------------------------------
			fwrite($fp,$content);
		//--------------------------------------------------
		// Then close the file
		//----------------------------------------------
			fclose($fp) or die ("Error closing file!");
Hope it makes sense and apologies for the n00b question!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Maybe because of different linebreaks.

Code: Select all

$content = str_replace("\r\n", "\n", $content);
LOFer
Forum Newbie
Posts: 2
Joined: Mon Dec 04, 2006 6:48 am

Ummm

Post by LOFer »

:oops:

Danke!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I really hate it when something that simple causes almost untraceable problems because some wiseheimer wrote super-extra-strict-correct code but is unable to provide reasonable error handling</rant>
Post Reply