dongtanghuan1885 2014-09-08 21:32
浏览 99
已采纳

调用未定义的函数finfo_open()第43行

so here the code if you can help i have system taht allow admin o write article an uplod pictures ut when i crite only article and post it it's ok but when i add picture ith aticle and post it i have error Call to undefined function finfo_open() line 43

<?php 

    // RECUPERATION DES DONNEES DU FORMULAIRE
    // photo
        $newsPhotoAvant         = (isset($_POST['newsPhotoAvant']))?        formatage_from_post($_POST['newsPhotoAvant']) : '';
        $newsPhotoDelete        = (isset($_POST['newsPhotoDelete']))?       formatage_from_post($_POST['newsPhotoDelete']) : '';
        $newsPhotoLargeur       = (isset($_POST['newsPhotoLargeur']))?      formatage_from_post($_POST['newsPhotoLargeur']) : '';

    // -----------------
    // Gestion des photos supprimees
    if ($newsPhotoAvant!='' && $newsPhotoDelete=='ON')
    {
        // Suppression de l'ancienne Photo
        if(file_exists('../../'.REP_NEWS_PHOTO.$newsPhotoAvant)) {
            unlink('../../'.REP_NEWS_PHOTO.$newsPhotoAvant);
        }
        // -----------------
        // Suppression dans la base de donnees par UPDATE
        $update_query           = "UPDATE ".$NEWS_TABLE." ".
                                " SET news_photo    = '' ".
                                " WHERE news_id     = :newsId;";
      try {
        $pdo_update             = $pdo->prepare($update_query);
        $pdo_update->bindValue(':newsId',       $newsId,        PDO::PARAM_INT);
        $pdo_update->execute();
      } catch (PDOException $e) { echo 'Erreur SQL : '. $e->getMessage().'<br/>'; die(); }
        // -----------------
    }

    // ----------------------------------
    // VERIFICATION / TRAITEMENT de la photo si uploadee
    // ----------------------------------
    $msgErreurPhoto             = '';   // message d erreur
    $traiterPhotoOK             = true; // (par defaut)

    if(isset($_FILES['newsPhoto']) && $_FILES['newsPhoto']['size']>0)
    {
        // -------------------------------------
        // extension du fichier uploadé (en minuscule)
        $file_Extension         = strtolower(pathinfo($_FILES['newsPhoto']['name'],PATHINFO_EXTENSION));

        // Type MIME réel du fichier (important : évite les fichiers NON valides, dont l'extension a été renommée)
    //  $finfo                  = new finfo(FILEINFO_MIME_TYPE, NULL); // Retourne le type mime
    //  $file_MimeType          = $finfo->file($_FILES['newsPhoto']['tmp_name']);

        // (alternative, si la CLASS finfo n'est pas supportée)
        $finfo                  = finfo_open(FILEINFO_MIME_TYPE); // Retourne le type mime à la extension mimetype
        $file_MimeType          = finfo_file($finfo, $_FILES['newsPhoto']['tmp_name']);
        finfo_close($finfo);

        // -------------------------------------
        // GESTION DES ERREURS
        // -------------------------------------
        // on vérifie les RESTRICTIONS sur les fichiers
        if (UPLOAD_ERR_OK<>0 && UPLOAD_ERR_FORM_SIZE==2) {
            $msgErreurPhoto     .= 'Taille de fichier trop important ('.FILE_SIZEMAX_PHOTO.' octets)<br />';
            $traiterPhotoOK     = false;
        }
        // -----------------
        // on vérifie la TAILLE MAXI
        elseif ($_FILES['newsPhoto']['size'] > FILE_SIZEMAX_PHOTO) {
            $msgErreurPhoto     .= 'Taille de fichier supérieure à la taille maxi autorisée ('.FILE_SIZEMAX_PHOTO.' octets)<br />';
            $traiterPhotoOK     = false;
        }
        // -----------------
        // on vérifie l'EXTENSION
        elseif(!in_array($file_Extension, explode(',', constant('FILE_EXTENSION_PHOTO')))) {
            $msgErreurPhoto     .= 'L\'extension ne correspond pas (Extensions acceptées  : <b>'.constant('FILE_EXTENSION_PHOTO').'</b>)<br />';
            if(in_array($file_MimeType, explode(',', constant('FILE_MIMETYPE_PHOTO')))) {
              $msgErreurPhoto   .= '<b>Attention</b> : Ce fichier est peut-être corrompu !<br />';
              $msgErreurPhoto   .= 'L\'extension ne correspond pas au type MIME !<br />';
            }
            $traiterPhotoOK     = false;
        }
        // -----------------
        // on vérifie le TYPE MIME
        elseif(!in_array($file_MimeType, explode(',', constant('FILE_MIMETYPE_PHOTO')))) {
            $msgErreurPhoto     .= 'Le type MIME ne correspond pas (Extensions acceptées  : <b>'.constant('FILE_EXTENSION_PHOTO').'</b>)<br />';
            if(in_array($file_Extension, explode(',', constant('FILE_EXTENSION_PHOTO')))) {
              $msgErreurPhoto   .= '<b>Attention</b> : Ce fichier est peut-être corrompu !<br />';
              $msgErreurPhoto   .= 'L\'extension ne correspond pas au type MIME !<br />';
            }
            $traiterPhotoOK     = false;
        }
        // -----------------
        if ($traiterPhotoOK===false) {
            $msgErreurPhoto     = '<b>Erreur (Photo)</b> :<br />'.$msgErreurPhoto.'Impossible d\'enregistrer le fichier.';
        }
        // -------------------------------------
        // si pas d'erreur : TRAITEMENT
        // -------------------------------------
        if ($traiterPhotoOK===true)
        {
            // --------------------
            // enregistement de la PHOTO sous forme id_nom-image(.jpg, ...)
            // NB : id etant unique (auto-increment), cela rend le nom de la photo unique
            $file_Upload        = $newsId.'_'.$_FILES['newsPhoto']['name'];
            $file_Upload        = formatage_nom_fichier($file_Upload); // remplacement des caracteres speciaux + tout en minuscules
            $file_Upload        = str_replace('.jpeg','.jpg',$file_Upload); // on remplace aussi .jpeg par .jpg
            // --------------------
            // enregistrement de la photo dans le dossier
            $temp = $_FILES['newsPhoto']['tmp_name'];
            move_uploaded_file($temp, '../../'.REP_NEWS_PHOTO.$file_Upload);
            // --------------------
            // REDIMENSIONNEMENT et SAUVEGARDE de la PHOTO (si necessaire)
            // ecraser (remplacer) la photo (meme rep, meme nom)
            $redimPHOTOOK       = fctredimimage($newsPhotoLargeur,0,'','','../../'.REP_NEWS_PHOTO,$file_Upload);
            // --------------------
            // SUPPRESSION des ANCIENNES PHOTOS (si necessaire) dans le dossier
            if ($newsPhotoAvant!='' && $newsPhotoAvant!=$file_Upload)
            {
                if(file_exists('../../'.REP_NEWS_PHOTO.$newsPhotoAvant)) {
                    unlink('../../'.REP_NEWS_PHOTO.$newsPhotoAvant);
                }
            }
            // -----------------
            // enregistrement du NOM dans la base de donnees par UPDATE
            $update_query       = "UPDATE ".$NEWS_TABLE." SET ".
                                " news_photo            = :file_Upload, ".
                                " news_photo_largeur    = :newsPhotoLargeur ".
                                " WHERE news_id         = :newsId;";
          try {
            $pdo_update         = $pdo->prepare($update_query);
            $pdo_update->bindValue(':file_Upload',      $file_Upload,       PDO::PARAM_STR);
            $pdo_update->bindValue(':newsPhotoLargeur', $newsPhotoLargeur,  PDO::PARAM_STR);
            $pdo_update->bindValue(':newsId',           $newsId,            PDO::PARAM_INT);
            $pdo_update->execute();
          } catch (PDOException $e) { echo 'Erreur SQL : '. $e->getMessage().'<br/>'; die(); }
            // -----------------
        }

    } // fin TRAITEMENT PHOTO
    // ---------------------------------------------------

?>
  • 写回答

1条回答 默认 最新

  • doulun5683 2014-09-08 21:53
    关注

    Looks like you haven't enabled the extension yet. Enable php_fileinfo.dll in your php.ini. If it doesn't work and if you're running PHP on windows, you can try installing Gnuwin.

    P.S. I strongly recommend you to update your PHP. PHP <5.4 lacks many features.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog