duankang8114 2015-10-21 14:59
浏览 41
已采纳

删除选择的图像

There is a web-site with an orders, where each order has attaches(pictures) which we could see, but not remove.(Because using PrettyPhoto) Also using Fat Free Framework.


What i did yet:

Made output window with oportunity of choosen pictures with checkboxes and button delete and attached JQuery when click on delete btn. It's works fine while i don't agree the confirmation. Then nothing happens, and that's so bad for me. I hope tomorrow it will be working.
Primary web-page(part)
<div id="fileDelete" class="modal modal-userinfo hide fade">
<?php
    $Attaches = GetOrderAttaches($orderDetail->getID(), ATTACH_OWNER_ACCESSOR);
?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Выберите файлы для удаления из заявки</h3>
</div>
<div class="modal-body">
    <form class="form-vertical">
        <fieldset>
            <div class="control-group">
                <label class="control-label" for="checkboxes">Прикреплённые файлы:</label>
                <div class="controls">
                    <ul class="thumbnails">
                        <?php foreach ($Attaches as $Attach) :?>
                            <li class="span1">
                                <label class="checkbox" for="checkboxes-<?php echo $Attach['AttachID']; ?>">
                                    <?php echo $Attach['FileName']; ?>
                                    <input type="checkbox" name="fileToDelete" id="checkboxes-<?php echo $Attach['AttachID']?>"
                                           value="<?php echo $Attach['AttachID']; ?>">

                                    <a href="<?php echo('/upload/files/' . $Attach['FileName']); ?>"
                                       class="thumbnail">
                                        <?php
                                            $thumbnail_src = (mb_strtolower(pathinfo($Attach['FileName'], PATHINFO_EXTENSION)) == 'pdf') ? 'pdf.jpg' : $Attach['FileName'];
                                        ?>
                                        <img src="<?php echo('/upload/files/thumbnail/' . $thumbnail_src); ?>"
                                             alt="<?php //echo $Attach['RealFileName'] ?> ">
                                    </a>
                                </label>
                            </li>
                        <?php endforeach ?>
                    </ul>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="modal-footer">
    <span class="btn btn-danger enabled">
        <span>Удалить</span>
        <input id="filedeletebtn" name="deletingfiles" type="button" multiple>
    </span>
</div>

Script responsible for deleting files on btnclick

    $('#filedeletebtn').on('click', function(){
    var iSelectedFiles = $('#fileDelete').find("input:checkbox:checked").serializeArray();
    var count = iSelectedFiles.length;
    if (count != 0) {
        var html = 'Вы действительно хотите удалить выбранные фото? Элементов: ' + count;
        bootbox.confirm(html, function (result) {
            if (result) {
                $.each(iSelectedFiles, function (index, file) {
                    $.ajax({
                        type: 'POST',
                        url: 'api/order/images/' + file.value,
                        data: file.value
                    })
                        .fail(function (file, textStatus, jqXHR) {
                            bootbox.alert('Возникла проблема при удалении изображений: </br>' + file.statusText);
                        });
                });
            }
        });
    } else {
        bootbox.alert('Выберите файлы для удаления!');
    }
});

In file api/index.php added

F3::route('POST /order/images/@ID [ajax]', 'OrderController->deleteImages');

In controller Order.php added

public function deleteImages()
{
    try {
        $data = $_POST['data'];
        $queryFileName = Dbh::getInstance()->prepare("DELETE FROM attaches WHERE attachID=?");
        $queryFileName->execute(array($data));
    } catch (Exception $e){
        $this->output['error'] = true;
        $this->output['message'] = $e->getMessage();
    }
}


So, how to make it alive?? Can't understand what's wrong.
  • 写回答

1条回答 默认 最新

  • doucheng3407 2015-10-23 14:52
    关注

    So... I did it! In controller file was needed to change row on:

    $data = $_POST['value'];
    

    In the script file where AJAX was needed to change row on:

    $.ajax({
          type: 'POST',
          url: 'api/order/images/' + file.value,
          data: file
    })
    

    Looks like it was small thing, but yesterday i spend all day for solving this problem) Hope, that my experience will help anybody.

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分