dov11020 2018-10-17 23:23
浏览 18

无法读取其他情况

I have a code that is used to display output of ajax using boostrap and codeigniter. The function of my program is when I press button upload and select files, it will upload automatically. If the file is image, it will show the image just uploaded, and if the file just uploaded is't image, it will show the font awesome. The code have if else condition between apostrophe. This is my code

$output .='
                    <div>
                      <ul class="detail-attachments clearfix">
                        <?php
                          foreach ($list_file as $file) { ?>
                            <li id="datas">
                              <?php
                                if ($file["tipe"]=="image/jpeg" or $file["tipe"]=="image/bmp" or $file["tipe"]=="image/png") { ?>
                                  <span class="detail-attachment-icon has-img">
                                    <a href="'.base_url().'assets/files/file_materi/'.$data["file_name"].'" target="_blank">
                                      <img src="'.base_url().'assets/files/file_materi/'.$data["file_name"].'">
                                    </a>
                                  </span>
                                <?php }
                                else { ?>
                                  <span class="detail-attachment-icon"><i class="fa fa-file-o"></i></span>
                                  <div id="nama_filenya">

                                    <?php 
                                      echo $data["file_name"];
                                      ?>
                                  </div>
                                <?php }
                              ?>
                              <div class="detail-attachment-info">
                                <button type="button" class="btn btn-danger btn-block btn-sm" data-toggle="modal" data-target="#konfirmasi_hapus<?php echo $data["id_file_materi"]; ?>">Hapus</button>
                                </a>
                              </div>
                            </li>

                          <?php }
                        ?>
                      </ul>
                    </div>
                ';

But when I run my code and try to upload files, the if else function isn't run. The result when I have selected files, the files is authomatically uploaded, but the display is the the file, font awesome icon, and the button. when I see the inspect element, the code php function become comment like below

<div>
                    <ul class="detail-attachments clearfix">
                      <!--?php
                        foreach ($list_file as $file) { ?-->
                          <li id="datas">
                            <!--?php
                              if ($file["tipe"]=="image/jpeg" or $file["tipe"]=="image/bmp" or $file["tipe"]=="image/png") { ?-->
                                <span class="detail-attachment-icon has-img">
                                  <a href="http://localhost/ci_sc/assets/files/file_materi/camila-cabello-wonderland7.jpg" target="_blank">
                                    <img src="http://localhost/ci_sc/assets/files/file_materi/camila-cabello-wonderland7.jpg">
                                  </a>
                                </span>
                              <!--?php }
                              else { ?-->
                                <span class="detail-attachment-icon"><i class="fa fa-file-o"></i></span>
                                <div id="nama_filenya">
                                  <!--?php 
                                    echo $data["file_name"];
                                    ?-->
                                </div>
                              <!--?php }
                            ?-->
                            <div class="detail-attachment-info">
                              <button type="button" class="btn btn-danger btn-block btn-sm" data-toggle="modal" data-target="#konfirmasi_hapus<?php echo $data[" id_file_materi"];="" ?="">"&gt;Hapus</button>

                            </div>
                          </li>

                        <!--?php }
                      ?-->
                      <!-- <li id="upload_files"></li> -->
                    </ul>
                  </div>

Can someone help me to solve my problem so that the php function can be read by the system.

Thank you in advance

  • 写回答

2条回答 默认 最新

  • dongzhuo1880 2018-10-18 02:06
    关注

    You can use an output buffer to tidy-up your codes.

    <?php
    ob_start();
    ?>
    <div>
      <ul class="detail-attachments clearfix">
        <?php
          foreach ($list_file as $file) { ?>
          <li id="datas">
            <?php
                if ($file["tipe"]=="image/jpeg" or $file["tipe"]=="image/bmp" or $file["tipe"]=="image/png") { ?>
              <span class="detail-attachment-icon has-img">
                    <a href="'.base_url().'assets/files/file_materi/'.$data["file_name"].'" target="_blank">
                      <img src="'.base_url().'assets/files/file_materi/'.$data["file_name"].'">
                    </a>
                  </span>
              <?php }
                else { ?>
              <span class="detail-attachment-icon"><i class="fa fa-file-o"></i></span>
              <div id="nama_filenya">
    
                <?php 
                      echo $data["file_name"];
                      ?>
              </div>
              <?php }
              ?>
              <div class="detail-attachment-info">
                <button type="button" class="btn btn-danger btn-block btn-sm" data-toggle="modal" data-target="#konfirmasi_hapus<?php echo $data[" id_file_materi "]; ?>">Hapus</button>
                </a>
              </div>
          </li>
    
          <?php }
        ?>
      </ul>
    </div>
    <?php
    $output = ob_get_clean();
    ?>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么