Welcome Guest, Not a member yet? Register   Sign In
Uploading file into directory
#1

Does somebody knows how to upload a file into a specific folder?

I'm working on a blog page in which I need to display the picture that comes with the published post. Right now I made it to show a "noimage.jpg" if there's not image uploaded but so far all the posts that I have published have their own images.


It keeps showing the "noimage.jpg" file. The sending function its not even working(as all the files that I upload are nt being sent into the folder which I specified), can somebody guide me in how to fix this?

PHP Code:
           $slug str_replace(' ''-'$this->input->post('title'));
 
           $slug strtolower($slug);

            
// Upload Image
            
$upload['upload_path'] = './assets/img/posts';
            
$upload['allowed_types'] = 'gif|jpg|png';
            
$upload['max_size'] = '2048';
            
$upload['max_width'] = '2000';
            
$upload['max_height'] = '2000';
    
            
$this->load->library('upload'$upload);
    
            if (!
$this->upload->do_upload('post_image')) {
                
$filename './assets/img/noimage.jpg';
            } else {
                
$upload_data $this->upload->data();
                
$filename $upload_data['file_name'];
                
            }
            
            
// Page Data
 
           $data = array(
                
'title'            => $this->input->post('title'),
                
'slug'            => $slug,
                
'subject_id'    => $this->input->post('subject_id'),
                
'body'            => $this->input->post('body'),
                
'is_published'    => $this->input->post('is_published'),
                
'is_featured'    => $this->input->post('is_featured'),
                
'in_menu'        => $this->input->post('in_menu'),
                
'user_id'        => $this->session->userdata('user_id'),
                
'order'            => $this->input->post('order'),
                
'post_image'    => $filename,
 
           );
            
 
           // Insert Page
 
           $this->Post_model->add($data); 
here is my view in which I create/add new posts:
PHP Code:
<h2 class="page-header">Add Post</h2>
<?
php echo validation_errors('<p class="alert alert-danger">'); ?>
<?php 
echo form_open_multipart('admin/posts/add'); ?>
    <!-- Page Title -->
    <div class="form-group">
        <?php echo form_label('Post Title''title'); ?>
        <?php
            $data 
= array(
                
'name' => 'title',
                
'id'    => 'title',
                
'maxlength'    => '100',
                
'class'        => 'form-control',
                
'value'        => set_value('title')
            );
        
?>
        <?php echo form_input($data); ?>
    </div>
    
    <!-- Page Img -->
    <div class="form-group">  
        <?php echo form_label('Upload Image''post_image'?>
        <?php
            $data 
= array(
                
'name'    => 'post_image',
                
'class'    => 'form-control',
                
'value'    => set_value('post_image')
            );
        
?>
        <?php echo form_upload($data); ?>
    </div>

    <!-- Page Subject -->
    <div class="form-group">
        <?php echo form_label('Post Category''subject_id'); ?>
        <?php echo form_dropdown('subject_id'$subject_options0, array('class' => 'form-control')); ?>
    </div>

    <!-- Page Body -->
    <div class="form-group">
        <?php echo form_label('Body''body'); ?>
        <?php
            $data 
= array(
        
        'name'          => 'body',
        
        'id'            => 'body',
        
        'class'         => 'form-control',
        
        'value'            => set_value('subject')
            );
        
?>
        <?php echo form_textarea($data); ?>
    </div>

    <!-- Publish -->
    <div class="form-group">
        <?php echo form_label('Published''is_published'); ?>
        <?php echo form_radio('is_published'1TRUE); ?> Yes 
        <?php echo form_radio('is_published'0FALSE); ?> No
    </div>

    <!-- Feature -->
    <div class="form-group">
        <?php echo form_label('Feature''is_featured'); ?>
        <?php echo form_radio('is_featured'1FALSE); ?> Yes 
        <?php echo form_radio('is_featured'0TRUE); ?> No
    </div>

    <!-- Menu -->
    <div class="form-group">
        <?php echo form_label('Add To Menu''in_menu'); ?>
        <?php echo form_radio('in_menu'1TRUE); ?> Yes 
        <?php echo form_radio('in_menu'0FALSE); ?> No
    </div>

    <!-- Order -->
    <div class="form-group">
        <?php echo form_label('Order''order'); ?>
        <input class="form-control" name="order" id="order" type="number">
    </div>

    <?php echo form_submit('mysubmit''Add Post', array('class' => 'btn btn-primary')); ?>
<?php 
echo form_close(); ?>
<script>
/*TinyMce editor*/
    tinymce.init({
    selector: "textarea",
    theme: "modern",
    image_advtab: true,    
    plugins: [
         "advlist autolink link image lists charmap  preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime  nonbreaking",
         "table contextmenu directionality template paste textcolor"
            ],
    toolbar: "insertfile undo redo | styleselect | bold underline italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | image link | code fullscreen"
     });
</script> 
I do Front-End development most of the time 
Reply
#2

Check if the folder you want to write to, has the right permissions (777).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB