Function codeigniter works in windows but not in linux

0

Develop this function to upload files to the server but I do not understand why it works in windows and not in linux 7 cent, so that it works in linux should something be configured? permissions or something? I already change permissions of the folders and also check the route apparently everything is fine, the size of the file also probe with several sizes and remove the size configuration but it does not work. Please I need to solve it since at work I use linux and at home windows

public function addProduct(){
            $archivo = $this->filePath();
            $result = $this->m->addProduct($archivo);
    $msg['success'] = false;
    $msg['type'] = 'add';
    if($result){
        $msg['success'] = true;
    }
    echo json_encode($msg);
}

    public function filePath(){

        $config['upload_path'] = realpath('../image/product/') ;
        $config['allowed_types'] = "*";//"gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG";
        $config['overwrite']     = TRUE;
        $config['max_size'] = "50000";
        $config['max_width'] = "2000";
        $config['max_height'] = "2000";

        $this->load->library('upload', $config);

        $res =  '';

        if ( ! $this->upload->do_upload('txtFoto') ) {
            $error = array('error' => $this->upload->display_errors());
            $res = 'hola no funciona'; 

        }else { 

            $file_data = $this->upload->data();
            $file_path = './image/product/'.$file_data['file_name'];
            $res = $file_path;

        } 
        return $res;
    }
    
asked by M.Antonio 25.05.2017 в 17:14
source

1 answer

0

Assuming you have activated the .htaccess to not use the index.php

view

<form action="<?= base_url('generals/upload_files/addProduct')?>" method="post" enctype="multipart/form-data">
    <input type="hidden" type="image" name="type">
    <input type="text" name="product_name">
    <input type="text" name="product_price">
    <input type="file" name="userfile">
    <input type="submit" value="Upload">
</form>

application / controllers / generals / upload_files.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Upload_files extends CI_Controller {
    public $images            = 'gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG';
    public $pdfs              = 'pdf';

    public function addProduct(){
        $type_file            = $this->input->post('type', TRUE);
        $info_product         = array(
                                      'name' => $this->input->post('product_name', TRUE),
                                      'price'=> $this->input->post('product_price', TRUE)
                                     );

        switch($type_file){
            case 'image':
                $info_file    = $this->_uploadFile($this->images);
                break;
            case 'pdf':
                $info_file    = $this->_uploadFile($this->pdfs);
                break;
        }

        $msg['success']       = false;

        $prod_id              = $this->model_insert_product->addInfoProduct($info_product);
        if( $info_file !== 'error'){
            $result           = $this->model_insert_product->addProduct($info_file, $prod_id);
            $msg['success']   = true;
        }

        $msg['type']          = 'add';

        echo json_encode($msg);
    }

    protected function _uploadFile($types){

        $config['upload_path']   = './image/product/');
        $config['allowed_types'] = $types;
        $config['overwrite']     = TRUE;
        $config['max_size']      = "50000";
        if( strpos($types, 'jpg')){
            $config['max_width'] = 0;
            $config['max_height']= 0;
        }

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload()){
            log_message('error', $this->upload->display_errors());
            $res                 = 'error'; 
        }
        else{ 
            $file_data           = $this->upload->data();
            $res                 = $file_data->full_path;
        }

        return $res;
    }

application / models / model_insert_product.php

function addInfoProduct($info_product){
    $this->db->insert('table1', $info_product);

    return $this->db->insert_id();
}

function addProduct($info_file, $prod_id){
    $this->db->insert('table2', array('fk_table1' => $product_id, 'img_path' => $info_file));

    return $this->db->insert_id();
}
    
answered by 05.06.2017 в 20:04