Check if the storage of the image path was correct in codeigther

0

I need to upload or store some files, which I keep the path in the database and that file I send to a folder with a main route. The error comes when I upload my file, it saves me but it does not check that it is really good, for it I put it that when uploading the file the state sends a green check if I charge it correctly.

But I get this error after asking so much why I did not load the array: Array ([name] = > Array ([0] => CONSOLIDATIONOREQUERIMIENTO.docx) [type] => Array ([0] => application / vnd.openxmlformats-officedocument.wordprocessingml.document) [tmp_name] = > Array ([0] = > C: \ xampp \ tmp \ php9AE1.tmp) [error] = > Array ([0] => 0) [size] => Array ([0] = & gt ; 131975)) 11

I leave the code so they can understand what I mean:     public function others_data () {// Reload other attachments (DETAILS OF MANAGEMENT)         $ nro = count ($ _ FILES ["file_other"] ["name"]);

    for ($i = 0; $i < $nro; $i++) {
        print_r($_FILES["archivo_otros"]);
        $file_name = $_FILES["archivo_otros"]["name"][$i];
        $file_size = $_FILES["archivo_otros"]["size"][$i];
        $file_type = $_FILES["archivo_otros"]["type"][$i];
        if ($file_name != "") {
            $nombre_archivo = $file_name;

            if (!file_exists('./files/others/' . $nombre_archivo)) {
                mkdir('./files/others/', 0777, true);
            }
            $path = "files/others";

            copy($_FILES["archivo_otros"]['tmp_name'][$i], $path . '/' . $nombre_archivo);

            $datos = array(
                'nombre' => $nombre_archivo,
                'ruta' => 'C:/xampp/htdocs/cnr/' . $path . '/',
                'tipo' => 'Otros',
                'detalle_actividad_id' => $_POST['idDetalle']
            );

            $this->submit_model->form_insert($datos, 'archivos_adjuntos');
        } else {
            $errors = array('error' => 'Error con: {$file_name}');
        }
    }
    $where=array(
        'field' => 'detalle_actividad_id',
        'condition' => $_POST['idDetalle']);
    $datos_2['estatus_control'] = 'En Trámite';
    $this->submit_model->form_update($datos_2, 'control_actividades', null, $where);
    $url = base_url('process/index') . '?cty=' . $_POST['cty'] . '&cpy=' . $_POST['cpy'] . '&prc=' . $_POST['prc'] . '&lab=' . $_POST['lab'] . '&sol=' . $_POST['app'];
    //redirect($url, "refresh");
}

Comment the line where the refresh is to know what you were giving me

    
asked by Luna 04.09.2017 в 08:13
source

1 answer

0

Try this code:

public function others_data() { 

    //Recarga de otros archivos adjuntos (DETALLES DE GESTIÓN)
    $nro = count($_FILES["archivo_otros"]["name"]);


    echo "<pre>"; print_r( $_FILES[ "archivo_otros" ]); echo "</pre>"; //Traza

    for ($i = 0; $i < $nro; $i++) {
        //print_r($_FILES["archivo_otros"]);
        $file_name = $_FILES["archivo_otros"]["name"][$i];
        $file_size = $_FILES["archivo_otros"]["size"][$i];
        $file_type = $_FILES["archivo_otros"]["type"][$i];

        if ( $file_name != "" ) {
            $path = "files/others/";
            if (!is_dir( $path )) {
                mkdir('./files/others/', 0777, true);
            }

            $file_path = $path . $file_name;
            echo "File path: " . $file_path . "<br>"; //Traza
            copy( $_FILES["archivo_otros"]['tmp_name'][$i], $file_path );

            $datos = array(
                'nombre' => $file_name,
                'ruta' => 'C:/xampp/htdocs/cnr/' . rtrim ( $path , "/" ),
                'tipo' => 'Otros',
                'detalle_actividad_id' => $_POST['idDetalle']
            );

            $res = $this->submit_model->form_insert($datos, 'archivos_adjuntos');
            var_dump( $res ); //trace

        } else {
            $errors = array('error' => 'Error con: {$file_name}');
        }
    }
    die( "stop" ); //Trace

    $where=array(
        'field' => 'detalle_actividad_id',
        'condition' => $_POST['idDetalle']);
    $datos_2['estatus_control'] = 'En Trámite';
    $this->submit_model->form_update($datos_2, 'control_actividades', null, $where);
    $url = base_url('process/index') . '?cty=' . $_POST['cty'] . '&cpy=' . $_POST['cpy'] . '&prc=' . $_POST['prc'] . '&lab=' . $_POST['lab'] . '&sol=' . $_POST['app'];
    //redirect($url, "refresh");
}

I have entered traces to see where you are going, with a comment of //trace at the end of the line, you should delete them later. The Ultima finalizes the script to know if you get to that point without errors, where you should have already saved the files.

    
answered by 04.09.2017 в 10:22