EAjaxUpload:onCancel仍然上传图像

时间:2014-06-16 06:43:16

标签: javascript php ajax yii yii-extensions

我正在使用EAjaxUpload在我的项目中上传图片,但是当我取消该过程时,它仍会保存我上传的图片。

以下是代码:

  <div class="thumbnail">
        <?php
            if ($model_account->profile_picture == 0) {
                echo '<img id="upload-preview" src="/resources/images/image_sample.jpg" style="max-width: 500px;" class="thumbnail">';
            } else {
                echo '<img id="upload-preview" src="/'.$page_data['thumb_small_url'].'" style="max-width: 500px;" class="thumbnail">';
            }
        ?>
    </div>
    ...
    <div class="controls" style="margin:10px 0 0 140px;">
        <script>
            var profile_picture_source = document.getElementById('upload-preview').src; //only to get the reference of the previous profile picture to be used during onCancel
        </script>                               
        <?php
            $this->widget('ext.EAjaxUpload.EAjaxUpload',
                            array(
                                'id'=>'uploadFile',
                                'config'=>array(
                                             'action'=>Yii::app()->request->baseUrl.'/school/Profile/UploadPhoto',
                                             'allowedExtensions'=>array("jpg", "jpeg", "gif", "png"),//array("jpg","jpeg","gif","exe","mov" and etc...
                                             'sizeLimit'=>4*1024*1024,// maximum file size in bytes
                                             //'minSizeLimit'=>1*1024*1024,// minimum file size in bytes
                                             'onSubmit'=> "js:function(id, fileName, responseJSON){
                                                                                var loading_image_url = '/resources/images/loader.gif'; //loading or progress image while uploading
                                                                                $('#qq-upload-preview').css('width','31px');
                                                                                document.getElementById('upload-preview').src = loading_image_url;
                                                                        }",
                                             'onComplete'=>"js:function(id, fileName, responseJSON){
                                                                                var upload_image_url = '".Yii::app()->request->baseUrl."/' + responseJSON['folder'] +  responseJSON['filename'];
                                                                                document.getElementById('upload-preview').src = upload_image_url;
                                                                                $('.qq-upload-success').css('display','none');
                                                                                $('.qq-upload-fail').css('display','none');
                                                                                $('#hidden_image_field').attr('value',responseJSON['filename']);
                                                                                $('#hidden_image_folder').attr('value',responseJSON['folder']);
                                                                                $('#asset_id').attr('value',responseJSON['asset_id']);
                                                                        }",
                                             'messages'=>array(
                                                                                 'typeError'=>"Please upload valid data.",
                                                                                 'sizeError'=>"4MB is maximum",
                                                                                'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
                                                                                'emptyError'=>"{file} is empty, please select files again without it.",
                                                                                 'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled.",
                                                                            ),
                                             'showMessage'=>"js:function(message){
                                                                                        document.getElementById('upload-image-err').innerHTML = message;
                                                                                }",
                                             'onCancel'=>"js:function(){
                                                                            document.getElementById('upload-preview').src = profile_picture_source;
                                                                        }",
                                            )
                            ));
        ?>

我已经对我遇到问题的行发表了评论,我仍然无法弄清楚为什么即使我取消也接受了图像。我尝试在onCancelonComplete中发出提醒,然后点击onCancel,分别显示两个提醒。这是否意味着onCancel每次都不起作用?

0 个答案:

没有答案