我有一个代码,用于使用boostrap和codeigniter显示ajax的输出。我的程序的功能是当我按下按钮上传并选择文件时,它将自动上传。如果文件是图像,则将显示刚刚上传的图像,如果文件是非图像,则将显示超赞的字体。该代码在撇号之间有其他条件。这是我的代码
$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>
';
但是,当我运行代码并尝试上传文件时,if else函数未运行。选择文件后的结果是,文件会被自动上传,但显示的是文件,字体真棒图标和按钮。当我看到inspect元素时,代码php函数变成如下注释
<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"];="" ?="">">Hapus</button>
</div>
</li>
<!--?php }
?-->
<!-- <li id="upload_files"></li> -->
</ul>
</div>
有人可以帮助我解决我的问题,以便系统可以读取php函数。
提前谢谢
答案 0 :(得分:0)
您可以使用输出缓冲区来整理代码。
...
function obj = SomeClass()
S = dbstack(1, '-completenames');
S(1).file
end
...
>> test()
ans =
'some_path/test.m'
答案 1 :(得分:0)
您有两种选择:
我个人找到了输出缓冲清洁器。这是您的代码示例:
<?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="<?php echo base_url() ?>assets/files/file_materi/<?php echo $data["file_name"] ?>" target="_blank">
<img src="<?php echo base_url() ?>assets/files/file_materi/<?php echo $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();
否则,您将必须执行以下操作:
<?php
$output =
'<div>
<ul class="detail-attachments clearfix">';
foreach ($list_file as $file) {
$output .= '<li id="datas">';
if ($file["tipe"]=="image/jpeg" or $file["tipe"]=="image/bmp" or $file["tipe"]=="image/png") {
$output .= '<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>';
}
else {
$output .= '<span class="detail-attachment-icon"><i class="fa fa-file-o"></i></span>
<div id="nama_filenya">
'.$data["file_name"].'
</div>';
}
$output .= '<div class="detail-attachment-info">
<button type="button" class="btn btn-danger btn-block btn-sm" data-toggle="modal" data-target="#konfirmasi_hapus'.$data["id_file_materi"].'">Hapus</button>
</a>
</div>
</li>';
}
$output .= '
</ul>
</div>';