无法在codeigniter

时间:2017-04-29 15:34:07

标签: php html codeigniter

我&我的同事一直试图上传各种扩展名为.jpg / .png / .docs / .xls的文件。我们在文件上传期间遇到了几个问题,StackOverflow帮助了我们很多。但是我们仍然无法解决一个问题,即代表上传的.xls / .docx文件的图标!似乎这些扩展没有任何默认图标。因此,必须使用图像来表示它们。因此,我们使用100 * 100大小的图像来表示.docs& .xls文件!

以下是相同的代码: -

   <html>
  <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>


        <link href="<?php echo base_url("assets/css/bootstrap.css"); ?>" rel="stylesheet" type="text/css" />
        <link href="<?php echo base_url("assets/css/bootstrap.min.css"); ?>" rel="stylesheet" type="text/css" />
        <link href="<?php echo base_url("assets/css/font-awesome.min.css"); ?>" rel="stylesheet" type="text/css" />
        <link href="<?php echo base_url("assets/css/AdminLTE.css"); ?>" rel="stylesheet" type="text/css" />

        <link href="<?php echo base_url("assets/css/Neww3.css"); ?>" rel="stylesheet" type="text/css" >
        <link href="<?php echo base_url("assets/img/word.jpg");?>" >


    </head>
    <body>
<?php $thumbnails = array_chunk( $files, 3 );
            ?>
                   <?php if(!empty($files)) { 
                        foreach($thumbnails as $files) { ?>
                        <div class="row">
                        <?php foreach($files as $file) { 
                        $filename = $file['file_name']; ?>
                            <div class="col-md-4">
                                <div class="thumbnail">
                                <?php $parts=pathinfo($filename); 
                                $extension = $parts['extension'];       

                                switch ($extension) {
  case 'xls':
  echo '<a href="'.base_url('uploads/files/'.$file['file_name']).'"> 
 <img src="http://localhost/my_proj/index.php/upload_files/assets/img/xcel.jpg" alt="" />
  <p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';
  break;

   case 'docx':
  echo '<a href="'.base_url('uploads/files/'.$file['file_name']).'"> 
  <img src="http://localhost/my_proj/index.php/upload_files/assets/img/word.jpg" alt="" />
  <p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';
  break;

case 'jpg':
$bu = base_url('uploads/files/'.$file['file_name']);
$d = date("j M Y",strtotime($file['created']));
echo '<a href="'.$bu.'"><img src="'.$bu.'"/><p>Uploaded On '.$d.'</p></a>';
break;

 default:
  echo '<a href="'.base_url('uploads/files/'.$file['file_name']).'"> 
  <img src="http://localhost/my_proj/index.php/upload_files/assets/img/client5.png" alt="" >
  <p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';

}

?>
                  </div>
                            </div>
                        <?php } ?>
                    </div>
                <?php } ?>
            <?php } else { ?>
                <p>Image(s) not found.....</p>
            <?php } ?>
         </div>
         </body>
         </html>

注意:图像放在文件夹my_proj / asset / img / word.jpg中 Output of the code 最后一个块包含.docs文件!它被下载但没有显示我使用了图标This is the image I am using as an icon for the file

的图像

1 个答案:

答案 0 :(得分:3)

你设置路径的方式是不正确的。试试这样它会起作用!!

 <img src="http://localhost/my_proj/assets/img/word.jpg" alt="" />
  <p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';
  break;