The14thGOD Posted August 7, 2009 Share Posted August 7, 2009 I created a CMS that makes new pages from existing pages. It makes almost exact duplicates except that an ID is added and a variable is changed. I downloaded the created files and they are perfect duplicates of the pre-existing files. The problem is it would ignore my includes, so I changed them to absolute paths and it worked. Now I'm glad that it works but I want to know why the includes have to be absolute paths? They are in the same folder as the rest of the pages using the same lines so it's not a path issue? The code is identical. On top of this my Database calls have to be put directly into the file (thus defeating the include purpose...). Is there any kind of correction I need to put into the following code so I don't have to make them absolute paths? Or is there a different way to create pages from existing ones than the method below? <?php import_request_variables('pg'); if($send=='send'){ include('db connection script'); //Insert data into databases $newpage = "$page_link".".php"; $query = "a query') "; mysql_query($query); include('includes/random_gen.php'); $pageid = get_rand_id(10); $query2 = "a query"; mysql_query($query2); //create new files //create new pages, front end page, back end page switch($layout){ case 1: $filename = '../templates/three_cols.php'; $filename2 = 'templates/three_cols.php'; break; //etc etc } //open files for reading $fh = fopen ($filename, "r") or die ("couldn't open file"); $fh2 = fopen ($filename2, "r") or die ("couldn't open file"); //get data from files $data = fread($fh,filesize($filename)); $data2 = fread($fh2,filesize($filename2)); //close files fclose($fh); fclose($fh2); //new files $fh = fopen("../$newpage","w") or die ("couldn't make file"); $fh2 = fopen("$newpage","w") or die ("couldn't make file2"); //replace content in the data $data = str_replace('0000000000',"$pageid",$data); $data2 = str_replace('0000000000',"$pageid",$data2); //Proper navigation heading? switch($parent_page){ case 1: //home $data = str_replace('<body>','<body id="page1">',$data); $data2 = str_replace('<body>','<body id="page1">',$data2); break; //etc } //write the data into the files fwrite($fh,$data); fwrite($fh2,$data2); //close files fclose($fh); fclose($fh2); //set permissions chmod("../$newpage",644); chmod("$newpage",0644); //end file creation header("Location: $newpage"); exit(0); } ?> The include code is a normal include: <?php include('includes_folder/file.php') ?> I don't see how this would break it but does it matter if the pre-existing files are in a "templates" folder? There is no "includes" folder in there but I'm just copying the data of the files and putting it outside the "templates" folder where the include path is correct. If there are any improvements that can be made please let me know, I'd really like to just use relative paths for future changes/maintenance etc. Any and all help is much appreciated, Thanks, Justin Quote Link to comment Share on other sites More sharing options...
trq Posted August 7, 2009 Share Posted August 7, 2009 A more important question. Why are you copying files around to produce content? Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted August 10, 2009 Author Share Posted August 10, 2009 because I thought this would be the quickest way to create this CMS for a site with a bunch of different layouts and other variables and to avoid mod_rewrite (I'm not great at that yet...) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.