����C�  
Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/html/admin/productimages/clean.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4
var/www/html/admin/update-price.php000066400000023651150632152350013322 0ustar00 $maxFileSize) { $_SESSION['msg'] = 'El archivo es demasiado grande. El tamaño máximo permitido es 5MB.'; header("Location: update-price.php"); exit(); } // Procesar el archivo CSV try { $handle = fopen($_FILES['excel']['tmp_name'], "r"); if ($handle === false) { throw new Exception("No se pudo abrir el archivo."); } // Iniciar transacción para mejor manejo de errores // Asegúrate de que $con es tu objeto de conexión mysqli mysqli_begin_transaction($con); $updateCount = 0; $skippedRows = 0; $errors = []; $lineNum = 0; // Para llevar un conteo de la línea actual en el CSV while (($data = fgetcsv($handle, 0, ';')) !== false) { $lineNum++; // Si la primera línea es el encabezado, la omitimos if ($lineNum == 1) { // Esto asume que la línea 1 es siempre el encabezado $skippedRows++; // Contamos esta línea como "saltada" si lo deseas continue; // Pasa a la siguiente iteración del bucle, ignorando esta línea } // Validar que la fila tenga al menos 2 columnas (código y precio) if (count($data) < 2) { $errors[] = "Línea " . $lineNum . ": Fila con formato incorrecto. Se esperaban al menos 2 columnas."; $skippedRows++; continue; } $codigo_excel = trim($data[0]); $precio = trim($data[1]); // Validar que el código sea texto (no vacío y no numérico puro) // Se ha ajustado la validación para permitir códigos que contengan números y letras. // Si esperas solo letras, la validación original `is_numeric` es más estricta. if (empty($codigo_excel)) { $errors[] = "Línea " . $lineNum . ": Código del producto vacío."; $skippedRows++; continue; } // Validar que el precio sea numérico y positivo // str_replace(',', '.', $precio) para manejar comas como separadores decimales $precio = str_replace(',', '.', $precio); if (!is_numeric($precio) || (float)$precio < 0) { $errors[] = "Línea " . $lineNum . ": Precio inválido ('" . htmlentities($data[1]) . "'). Debe ser un número positivo."; $skippedRows++; continue; } // Convertir el precio a float explícitamente y formatearlo a 2 decimales $precio = number_format((float)$precio, 2, '.', ''); // Escapar el código para la consulta SQL $codigo_excel = mysqli_real_escape_string($con, $codigo_excel); // Usar consulta preparada para mayor seguridad y eficiencia $query = "UPDATE products SET productPrice = ?, updationDate = NOW() WHERE codigo = ?"; $stmt = mysqli_prepare($con, $query); if ($stmt === false) { throw new Exception("Error al preparar la consulta: " . mysqli_error($con)); } mysqli_stmt_bind_param($stmt, "ds", $precio, $codigo_excel); // "d" para double (precio), "s" para string (código) $result = mysqli_stmt_execute($stmt); if ($result) { // Solo contar si realmente se afectó una fila if (mysqli_stmt_affected_rows($stmt) > 0) { $updateCount++; } else { // Si no se actualizó, podría ser que el código no existe o el precio es el mismo $errors[] = "Línea " . $lineNum . ": No se encontró el producto con código '" . htmlentities($codigo_excel) . "' o el precio ya era el mismo."; $skippedRows++; } } else { $errors[] = "Línea " . $lineNum . ": Error al ejecutar la actualización para el código '" . htmlentities($codigo_excel) . "': " . mysqli_stmt_error($stmt); $skippedRows++; } mysqli_stmt_close($stmt); } fclose($handle); // Si hay errores, no cometer la transacción if (!empty($errors)) { mysqli_rollback($con); $_SESSION['msg'] = "Se actualizaron $updateCount precios correctamente, pero hubo " . count($errors) . " errores y $skippedRows filas omitidas:
" . implode("
", $errors); } else { mysqli_commit($con); $_SESSION['msg'] = "Se actualizaron $updateCount precios correctamente."; } header("Location: update-price.php?updation=1"); exit(); } catch (Exception $e) { mysqli_rollback($con); $_SESSION['msg'] = 'Error al procesar el archivo: ' . $e->getMessage(); header("Location: update-price.php"); exit(); } } // Mostrar mensaje de éxito si se redirige con updation if (isset($_GET["updation"])) { // Si ya hay un mensaje en $_SESSION['msg'] (por ejemplo, si hubo errores), se mantiene. // Si no, se asigna un mensaje genérico de éxito. $_SESSION['msg'] = $_SESSION['msg'] ?? 'Se completó la operación de actualización de precios.'; } ?> FiberNet | Actualización de Precios

Actualizar Precios de Productos

Resultado:


Selecciona un archivo CSV con el formato: código,precio

Ejemplo de contenido CSV: