mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta backend meter en bbdd y borrar antiguos
This commit is contained in:
@ -799,14 +799,36 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
public function upload_files(){
|
||||
|
||||
if(!empty($_FILES) && $_FILES['file']>0){
|
||||
foreach ($_FILES['file'] as $file) {
|
||||
if ($file->isValid() && !$file->hasMoved()) {
|
||||
$file->move(WRITEPATH . 'uploads');
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
// Comprobar si se han subido archivos
|
||||
if (!empty($_FILES['file'])) {
|
||||
$files = $_FILES['file'];
|
||||
|
||||
// Iterar sobre los archivos
|
||||
for ($i = 0; $i < count($files['name']); $i++) {
|
||||
// Aquí puedes acceder a las propiedades del archivo
|
||||
$name = $files['name'][$i];
|
||||
$type = $files['type'][$i];
|
||||
$tmp_name = $files['tmp_name'][$i];
|
||||
$error = $files['error'][$i];
|
||||
$size = $files['size'][$i];
|
||||
|
||||
// Crear un hash único a partir del nombre del archivo
|
||||
$hash = hash('sha256', $name);
|
||||
// Usar el hash como el nuevo nombre del archivo
|
||||
$new_name = $hash . '.' . pathinfo($name, PATHINFO_EXTENSION);
|
||||
|
||||
// Se sube el fichero
|
||||
// Pero primero se comprueba que la carpeta presupuestos exista
|
||||
if (!is_dir(WRITEPATH . 'uploads/presupuestos')) {
|
||||
mkdir(WRITEPATH . 'uploads/presupuestos', 0777, true);
|
||||
}
|
||||
move_uploaded_file($tmp_name, WRITEPATH . 'uploads/presupuestos/' . $new_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return json_encode(['message' => 'Archivos subidos correctamente']);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user