Commit 81a3248a by David Villalba

Cambiar el upload file a trait

parent a327f521
<?php
/**
* Created by PhpStorm.
* User: admin
* Date: 23/07/2015
* Time: 14:03
*/
class Controller_Uploadfile
{
/**
* @desc: Sube a carpeta temporal correspondiente el archivo para que quede pendiente de subir
* @param $id
* @param $path
* @return string
*/
public function upload_pagos_file($id, $path)
{
// Configuracion del fichero
$config = array(
'path' => DOCROOT . "files/$path/" . $id,
'randomize' => false,
);
$config['path']= str_replace('\\','/',$config['path']);
// Procesa el archivo subido
Upload::process($config);
Log::error("PATH UPLOAD". $config['path']);
// si no hay ficheros erroneos, guarda el fichero de acuerdo con la configuracion
if (Upload::is_valid()) {
Upload::save();
$file = Upload::get_files();
// ubicación del fichero con el nombre asignado.
$uploaded_file = $file[0]['saved_to'] . $file[0]['saved_as'];
} else
$uploaded_file = 'error';
return $uploaded_file;
}
/**@desc: Guarda en el modelo de datos la direccion y el ID del archivo
* @param $path
* @return mixed
* @throws Exception
*/
public function saveFile($path, $id)
{
if($path=="compraventa"){
$file = Model_CompraventaDocumento::forge();
}else{
$file = Model_ContratoDocumento::forge();
}
$filePath = $this->upload_pagos_file($id, $path);
$filePath= str_replace('\\','/',$filePath);
Log::error("despuesd de guardar $filePath");
$filePath= explode("/",$filePath);
if(sizeof($filePath)<=0){
Log::error("Ocurrio un error relacionado con el path al guardar");
return false;
}
$filePath= $filePath[sizeof($filePath)-1];
Log::error("PATH=>$filePath ");
$file->ds = $filePath;
if($path=="compraventa"){
$file->compraventa_id = $id;
}else{
$file->contrato_id = $id;
}
$this->path = $filePath;
$file->save();
$ret['id'] = $file->id;
$ret['path'] = $file->ds;
return $ret;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment