Overview
Comment: | Utiliser openBlob pour écrire les fichiers |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
1fb74fb690ab70e30bfa24c30a3782f7 |
User & Date: | bohwaz on 2020-03-01 18:44:53 |
Other Links: | branch diff | manifest | tags |
Context
2020-03-01
| ||
18:45 | Exiger d'avoir PHP 7.2 avant toute chose check-in: d834be67ff user: bohwaz tags: dev | |
18:44 | Utiliser openBlob pour écrire les fichiers check-in: 1fb74fb690 user: bohwaz tags: dev | |
2020-02-29
| ||
23:18 | Nouvelle version seulement compatible avec PHP 7.2+ check-in: 2f79c24d5f user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Fichiers.php from [630c28763b] to [10416ad902].
︙ | ︙ | |||
462 463 464 465 466 467 468 | } if (!is_uploaded_file($file['tmp_name'])) { throw new \RuntimeException('Le fichier n\'a pas été envoyé de manière conventionnelle.'); } | < < < < < < < < < < < < < < < < < < < < < < < | 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | } if (!is_uploaded_file($file['tmp_name'])) { throw new \RuntimeException('Le fichier n\'a pas été envoyé de manière conventionnelle.'); } $name = preg_replace('/\s+/', '_', $file['name']); $name = preg_replace('/[^\d\w._-]/ui', '', $name); return self::storeFile($name, $file['tmp_name']); } /** * Upload de fichier à partir d'une chaîne en base64 * @param string $name * @param string $content * @return Fichiers */ static public function storeFromBase64($name, $content) |
︙ | ︙ | |||
545 546 547 548 549 550 551 | $is_image = preg_match('/^image\/(?:png|jpe?g|gif)$/', $type); $db = DB::getInstance(); $db->begin(); // Il peut arriver que l'on renvoie ici un fichier déjà stocké, auquel cas, ne pas le re-stocker | | > > > | > | | < | | | < < > > | | > | 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | $is_image = preg_match('/^image\/(?:png|jpe?g|gif)$/', $type); $db = DB::getInstance(); $db->begin(); // Il peut arriver que l'on renvoie ici un fichier déjà stocké, auquel cas, ne pas le re-stocker if (!($id_contenu = $db->firstColumn('SELECT id FROM fichiers_contenu WHERE hash = ?;', $hash))) { $db->preparedQuery('INSERT INTO fichiers_contenu (hash, taille, contenu) VALUES (?, ?, zeroblob(?));', [$hash, (int)$size, (int)$size]); $id_contenu = $db->lastInsertRowID(); // Écrire le contenu $blob = $db->openBlob('fichiers_contenu', 'contenu', $id_contenu, 'main', SQLITE3_OPEN_READWRITE); if (null !== $content) { fwrite($blob, $content); } else{ fwrite($blob, file_get_contents($path)); } fclose($blob); } $db->insert('fichiers', [ 'id_contenu' => (int)$id_contenu, 'nom' => $name, 'type' => $type, 'image' => (int)$is_image, |
︙ | ︙ |