• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making Directory PHP Codeigniter

#1
Hi all, I have been working on a function where can create a folder on my file manger, using mkdir.

I would like to know does codeigniter have a helper for that I know the have a helper for creating files but have not see one for creating directories


PHP Code:
public function folder() {
$json = array();

$directory FCPATH 'image/catalog/' $this->input->get('directory');

if (
is_dir($directory)) {
 
  mkdir($directory '/' $this->input->post('folder'), 0777);
 
  $json['success'] = 'The folder ' $this->input->post('folder') . 'was created!';
} else {
 
  $json['error'] = 'The folder ' $this->input->post('folder') . 'was not created!';
}

$this->output->set_content_type('Content-Type: application/json');
$this->output->set_output(json_encode($json));

 


Code:
<!-- Create Folder -->
<script type="text/javascript">

$('#button-folder').popover({
    html: true,
    placement: 'bottom',
    trigger: 'click',
    title: 'New Folder',
    content: function() {
        html  = '<div class="input-group">';
        html += '  <input type="text" name="folder" value="" placeholder="New Folder" class="form-control">';
        html += '  <span class="input-group-btn"><button type="button" title="" id="button-create" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></span>';
        html += '</div>';
        
        return html;    
    }
});

$('#button-folder').on('shown.bs.popover', function() {
    $('#button-create').on('click', function() {
        $.ajax({
            url: 'admin/common/filemanager/folder/?directory=<?php echo $directory; ?>',
            type: 'post',        
            dataType: 'json',
            data: 'folder=' + encodeURIComponent($('input[name=\'folder\']').val()),
            beforeSend: function() {
                $('#button-create').prop('disabled', true);
            },
            complete: function() {
                $('#button-create').prop('disabled', false);
            },
            success: function(json) {
                if (json['error']) {
                    alert(json['error']);
                }
                
                if (json['success']) {
                    alert(json['success']);
                                        
                    $('#button-refresh').trigger('click');
                }
            },            
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    });    
});
</script>
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
PHP has a simple native function to do that, so no need for a helper really...
http://php.net/manual/en/function.mkdir.php
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.