rofl90 Posted March 30, 2008 Share Posted March 30, 2008 I'm trying to read a file and have it open for editing, when I save it changed it to what I specify in the form heres both codes, one for the functions, one for the form, and the error: <br /> <b>Fatal error</b>: Allowed memory size of 20971520 bytes exhausted (tried to allocate 1000000000 bytes) in <b>/home/fhlinux160/p/prowebdesigns.co.uk/user/htdocs/backend/classes/database.php</b> on line <b>112</b><br /> functions: (read is at the bottom): <?php /** * $db core */ class database { private $server; private $username; private $password; private $database; /** * __Construct() */ function __construct() { } /** * Connecting configuration */ public function connect($server, $username, $password, $database) { if ($server == NULL || $username == NULL || $database == NULL) { //TODO: error. } else { $this->server = $server; $this->username = $username; $this->password = $password; $this->database = $database; $this->database_connect (); } } /** * Emulating mysql_error() */ public function error($text) { echo "There has been an error. Please try again later. <br /><br /> " . $text; exit (); } /** * Emulating mysql_connect() */ private function database_connect() { $conn = @mysql_connect ( $this->server, $this->username, $this->password ); if ($conn == false) { $this->error ( mysql_error () ); } else { $this->select_db (); } } /** * Emulating mysql_select_db() */ private function select_db() { $select_db = @mysql_select_db ( $this->database ); if ($select_db == false) { $this->error ( mysql_error () ); } } /** * Emulating mysql_query() */ public function query($query_text) { $query = mysql_query ( $query_text ) or die ( mysql_error () ); return $query; } /** * Emulating mysql_fetch_array() */ public function fetch_array($query_object) { $fetch = mysql_fetch_array ( $query_object ); return $fetch; } /** * Emulating mysql_num_rows() */ public function num_rows($query_object) { $num = mysql_num_rows ( $query_object ); return $num; } /** * __Destruct() */ function __destruct() { unset ( $this->server ); unset ( $this->username ); unset ( $this->password ); unset ( $this->database ); mysql_close (); } /** * read_file() */ public function read_file($myFile, $mode) { $fp = fopen($myFile, $mode); $theData = fread($fp, 7000); fclose($fp); return $theData; } /** * write_file() */ public function write_file($myFile, $mode, $data2write) { $fp = fopen($myFile, $mode); $theData = fwrite($fp, $data2write); fclose($fp); return '1'; } } /** * Create $db if not existing already */ if (! isset ( $db )) { $db = new database ( ); } ?> form: <form name="changecss" action="" method="get"> <fieldset><legend>CSS File</legend> <select name="cssname" id="cssname"> <option value="frontend">Frontend CSS</option> <option value="backend" <?php if($_GET['cssname'] == "backend") { echo "selected=\"selected\""; }?>>Backend CSS</option> </select> <input type="submit" name="Submit" value="Change" /> </fieldset> </form> <form name="editcss" action="?a=save" method="post"> <fieldset><legend>File Name</legend> <input type="text" name="name_css" id="name_css" value="<?php if($_GET['cssname'] == "backend") { echo "Backend CSS"; } else { echo "Frontend CSS"; } ?>" /> </fieldset> <fieldset><legend>CSS Body</legend> <textarea rows="25" name="css_body" id="css_body"><?php if($_GET['cssname'] == "backend") { echo $db->read_file("css/style.css", "r+"); } elseif($_GET['cssname'] == "frontend") { echo $db->read_file("../css/style.css", "r+"); } else { echo $db->read_file("css/style.css", "r+"); } ?></textarea> </fieldset> <fieldset><legend>Edit CSS</legend> <input type="submit" name="submit" id="name_css" value="Edit CSS" /> </fieldset> </form> Link to comment https://forums.phpfreaks.com/topic/98680-memory-error/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.