Reputation: 594
public function save(){
$currentPage = $_SESSION['current_page'];
$content = $this->input->get_post("page_content"); // html content
$path = $this->paths('pages');
$page = $this->pages->db_get(array("id"=>$currentPage), true);
//echo $path . $page['filename'];
if(!is_dir($path)){
$fileHandle = fopen($path . $page['filename'] , 'w');
if(!fwrite($fileHandle, $content)) {
$this->errors[] = "Error saving page";
}
fclose($fileHandle);
}
echo json_encode($this->errors);
}
I receieve a html source file via ajax POST request which then i wish to write to a file as a string. The commented line would echo */home/sajt/public_html/application/data/users/[email protected]/websites/kobra/pages/glavna.php* which exists on the server. I believe and have checked that $path, $page and $content have the correct values needed since echoing the $path . $page['filename'] returns a valid path to the file, but still nothing happens, that is nothing is being written. What am i missing here?
Parent Directory permissions :
drwx------ 5 sajt sajt 4096 Aug 9 04:20 .
drwx------ 3 sajt sajt 4096 Aug 9 04:20 ..
drwxr-xr-x 2 sajt sajt 4096 Aug 9 04:20 header
drwxr-xr-x 2 sajt sajt 4096 Aug 9 04:20 pages
drwxr-xr-x 2 sajt sajt 4096 Aug 9 04:20 uploads
Directory "pages" permissions:
drwxr-xr-x 2 sajt sajt 4096 Aug 9 04:20 .
drwx------ 5 sajt sajt 4096 Aug 9 04:20 ..
-rw-r--r-- 1 sajt sajt 0 Aug 9 13:20 glavna.php
-rw-r--r-- 1 sajt sajt 1450 Aug 9 04:20 kontakt.php
Upvotes: 0
Views: 331
Reputation: 360592
if(!is_dir($path)){
you explicitly tell the script to skip the whole fopen/fwrite business, because as your code is written, whatever is in $path HAS to be a directory.
Most likely you simply want
if (is_dir($path)) {
^--- no !
Upvotes: 1