[eluser]srpurdy[/eluser]
Normally I try to avoid IIS7 servers, but a client of mine has it, and gotta use it. I'm curious as to the ftp class as well, as read_file() write_file() functions in the file helper.
Because I seem to be having an issue with a template editing controller I wrote, which uses the ftp class, to connect to make folders, or chmod directorys from 755 to 777, of course this isn't really possible on a windows server, but my problem below is unrelated to that.
Code:
function create()
{
#CREATION OF A NEW TEMPLATE FOLDER, DO FORM VALIDATION
$this->load->library('form_validation');
$this->form_validation->set_rules('new_folder', 'new_folder', 'required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
#VIEW FILE INFORMATION
$data['heading'] = "Create New Theme/Template";
$data['get_dir'] = directory_map('./themes/');
$data['get_dir_temp'] = directory_map('./system/application/views/themes/');
$data['page'] = 'admin/template/create_template';
$this->load->vars($data);
$this->load->view($this->_container);
}
else
{
#FTP CONNECT, TO BEGIN CREATING NEW FOLDER
$config = $this->ftp_one();
$this->ftp->connect($config);
#CREATE DIRECTORYS AND CLOSE FTP CONNECTION
$this->ftp->mkdir($this->input->post('new_folder'), DIR_WRITE_MODE);
$this->ftp->mkdir($this->input->post('new_folder') . '/img', DIR_WRITE_MODE);
$this->ftp->mkdir($this->input->post('new_folder') . '/js', DIR_WRITE_MODE);
$this->ftp->mkdir($this->input->post('new_folder') . '/css', DIR_WRITE_MODE);
$this->ftp->close();
#FTP CONNECT FOR CREATING SECOND THEME FOLDER
$config = $this->ftp_two();
$this->ftp->connect(@$config);
#CREATE DIRECTORYS AND CLOSE FTP CONNECTION
$this->ftp->mkdir($this->input->post('new_folder'), DIR_WRITE_MODE);
$this->ftp->close();
#VIEW FILE INFORMATION
$data['heading'] = "New Template Created!";
$data['page'] = 'admin/template/create_temp_success';
$this->load->vars($data);
$this->load->view($this->_container);
}
}
It seems to be crashing on this line
Code:
$this->ftp->mkdir($this->input->post('new_folder') . '/img', DIR_WRITE_MODE);
I don't actually know whats wrong because all I get is a 500 error.
It makes the first folder which you type into the new_folder field, but won't create the sub directory's after that or do anything past that line.
Does anyone have a solution to this?
Next problem I have is I have a read_file, write_file, it seems it can't read the file at all.
Code:
function modify_file_template()
{
#CHECK IF FILE INFORMATION IS IN SEGMENT 5, AND THEME NAME IS IN SEGMENT 4
if($this->uri->segment(4) == '' OR $this->uri->segment(5) == '')
{
echo "Direct Access Not Allowed";
}
else
{
#DO FORM VALIDATION
$this->load->library('form_validation');
$this->form_validation->set_rules('file_contents', 'file_contents', 'required');
if ($this->form_validation->run() == FALSE)
{
#VIEW FILE INFORMATION
$data['heading'] = "Modify File";
$data['get_dir'] = directory_map('./themes/');
$data['get_dir_temp'] = directory_map('./system/application/views/themes/');
foreach($data['get_dir'] as $data['dir'] => $data['dir_value'])
{
$data['get_files'] = directory_map('./themes/' . $this->uri->segment(4) . '/css/', TRUE);
}
foreach($data['get_dir_temp'] as $data['dir_temp'] => $data['dir_value_temp'])
{
$data['get_files_temp'] = directory_map('./system/application/views/themes/' . $this->uri->segment(4) . '/', TRUE);
}
$data['newfilesegment'] = str_replace('_php', '', $this->uri->segment(5));
$data['read_file'] = read_file('./system/application/views/themes/' . $this->uri->segment(4) . '/' . $data['newfilesegment'] . '.php');
$data['page'] = 'admin/template/modify_file_template';
$this->load->vars($data);
$this->load->view($this->_container);
}
else
{
#CONNECT TO FTP, TO BEGIN FILE SAVING PROCEEDURE
$config = $this->ftp_two();
$this->ftp->connect(@$config);
#String replace segment 5, remove _php extension
$data['newfilesegment'] = str_replace('_php', '', $this->uri->segment(5));
#chmod the directory and file selected to writeable (777)
$this->ftp->chmod('/' . $this->uri->segment(4) . '/', DIR_WRITE_MODE);
$this->ftp->chmod('/' . $this->uri->segment(4) . '/' . $data['newfilesegment'] . '.php', DIR_WRITE_MODE);
#SAVE THE FILE AFTER CHANGES ARE MADE (ON SUBMIT)
write_file('./system/application/views/themes/' . $this->uri->segment(4) . '/' . $data['newfilesegment'] . '.php', $this->input->post('file_contents'));
#Saving is complete, now protect the files/directorys via chmod to read/excute mode (755)
$this->ftp->chmod('/' . $this->uri->segment(4) . '/', DIR_READ_MODE);
$this->ftp->chmod('/' . $this->uri->segment(4) . '/' . $data['newfilesegment'] . '.php' , DIR_READ_MODE);
#Now close the ftp connection, and display flash data message of successful file written!
$this->ftp->close();
$msg = $this->lang->line('file_written');
$this->session->set_flashdata('flashmsg', $msg);
#redirect back to the selected template files list
redirect('admin/template/edit_file/' . $this->uri->segment(4));
}
}
}
I tried full server paths to no avail... Any suggestions on getting this to work?
Like I mentioned this code works perfectly on unix/linux servers.
Thanks