За последние 24 часа нас посетили 20362 программиста и 1089 роботов. Сейчас ищут 793 программиста ...

Загрузка файла с русским именем в PDO Crud

Тема в разделе "PHP и базы данных", создана пользователем era1fgg, 16 фев 2020.

Метки:
  1. era1fgg

    era1fgg Гость

    С нами с:
    16 фев 2020
    Сообщения:
    1
    Симпатии:
    0
    Доброго времени суток! Использую скрипт PDO Crud на локальном вебсервере. Кто подскажет как правильно реализовать загрузку файлов с русскими именами. Вот собственно его код загрузчика
    Код (Text):
    1. /**
    2.      * Upload files using html file control. You can apply various restriction to make file uploading more secure.
    3.      * @param   string  $fileName               file upload control
    4.      * @param   string $fileUploadPath          Path to upload file
    5.      * @param   int $maxSize                    Max size allowed, default is 10000000
    6.      * @param   array $allowedFileTypes         Allowed file types
    7.      *
    8.      * return   boolean                         return true if file uploaded successfully else false
    9.      */
    10.     function fileUpload($fileName, $fileUploadPath = "", $maxSize = 10000000, $allowedFileTypes = array()) {
    11.         if ($this->checkValidFileUpload($fileName, $fileUploadPath, $maxSize, $allowedFileTypes)) {
    12.             if (!is_dir($fileUploadPath) && $fileUploadPath) {
    13.                 mkdir($fileUploadPath);
    14.             }
    15.             $destinationFileName = time() . "_" . $fileName["name"];
    16.             $destinationPath = $fileUploadPath . $destinationFileName;
    17.             if (move_uploaded_file($fileName["tmp_name"], $destinationPath)) {
    18.                 $destinationPath = $fileUploadPath . $destinationFileName;
    19.                 $fileExt = $this->getFileExtension($destinationPath);
    20.                 if (in_array($fileExt, array("jpg", "gif", "png"))) {
    21.                     $newFileName = substr($destinationFileName, 0, strlen($destinationFileName) - strlen($fileExt) - 1);
    22.                     require_once(dirname(__FILE__) . "/library/abeautifulsite/SimpleImage.php");
    23.                     $img = new SimpleImage();
    24.                     if (isset($this->imageDimensions)) {
    25.                         foreach ($this->imageDimensions as $width => $height) {
    26.                             $resizeImg = $newFileName . "_" . $width . "_" . $height . "." . $fileExt;
    27.                             $newImage = $img->load($destinationPath)->resize($width, $height)->save($fileUploadPath . $resizeImg);
    28.                         }
    29.                     }
    30.  
    31.                     if (isset($this->watermark)) {
    32.                         $img->load($destinationPath)->overlay($this->watermark["overlay"], $this->watermark["position"], $this->watermark["opacity"], $this->watermark["xOffset"], $this->watermark["yOffset"])->save($destinationPath);
    33.                     }
    34.  
    35.                     if (isset($this->imageFlip)) {
    36.                         $img->load($destinationPath)->flip($this->imageFlip)->save($destinationPath);
    37.                     }
    38.  
    39.                     if (isset($this->imageThumbnail)) {
    40.                         $img->load($destinationPath)->thumbnail($this->imageThumbnail["width"], $this->imageThumbnail["height"], $this->imageThumbnail["focal"])->save($destinationPath);
    41.                     }
    42.  
    43.                     if (isset($this->imageCrop)) {
    44.                         $img->load($destinationPath)->crop($this->imageCrop["x1"], $this->imageCrop["y1"], $this->imageCrop["x2"], $this->imageCrop["y2"])->save($destinationPath);
    45.                     }
    46.  
    47.                     if (isset($this->imageText)) {
    48.                         $imgText = $this->imageText;
    49.                         $img->load($destinationPath)->text($imgText["text"], $imgText["font_file"], $imgText["font_size"], $imgText["color"], $imgText["position"], $imgText["x_offset"], $imgText["y_offset"], $imgText["stroke_color"], $imgText["stroke_size"], $imgText["alignment"], $imgText["letter_spacing"])->save($destinationPath);
    50.                     }
    51.                 }
    52.                 return $this->settings["uploadURL"] . $destinationFileName;
    53.             } else
    54.                 return false;
    55.         }
    56.  
    57.         return false;
    58.     }
     
  2. Sail

    Sail Старожил

    С нами с:
    1 ноя 2016
    Сообщения:
    1.591
    Симпатии:
    360
    При загрузке генерировать "кошерное" имя файла. Соответствие с оригинальным именем обеспечить записью в базе данных.
     
  3. artoodetoo

    artoodetoo Суперстар
    Команда форума Модератор

    С нами с:
    11 июн 2010
    Сообщения:
    11.068
    Симпатии:
    1.231
    Адрес:
    там-сям
    @era1fgg если коротко, никогда не сохраняй загружаемые файлы под их исходными именами. сочиняй новые имена.