Javascript EAjaxUpload:onCancel仍然上传图像
我正在使用Javascript EAjaxUpload:onCancel仍然上传图像,javascript,php,ajax,yii,yii-extensions,Javascript,Php,Ajax,Yii,Yii Extensions,我正在使用EAjaxUpload在我的项目中上载图像,但是当我取消该过程时,它仍然保存我上载的图像 代码如下: ... var profile\u picture\u source=document.getElementById('upload-preview').src//仅获取onCancel期间要使用的上一个配置文件图片的参考 <div class="thumbnail"> <?php if ($model_account-&
EAjaxUpload
在我的项目中上载图像,但是当我取消该过程时,它仍然保存我上载的图像
代码如下:
...
var profile\u picture\u source=document.getElementById('upload-preview').src//仅获取onCancel期间要使用的上一个配置文件图片的参考
<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;
}",
)
));
?>