Hi All,
I’m getting crazy with this problem, I have no idea how to solve it, let me explain…
I have a grid where there is a list of images, in each row there is thumb as preview image and a button to crop to let the user crop the image. When the user crop the image I also generate a new thumb from the image already cropped and I overwrite the images by saving them with the same name.
After the image is cropped, I refresh the grid by renderPartial, the problem is that the thumb isn’t refreshed, I don’t know if it’s a cache problem or something like this because I save the image with the same name it had before. It only works if I refresh the entire page, the renderPartial works fine because I have tried to render other view and it works.
Here is my code:
Action
//Crop from the orginal file and save it in different folder
if( is_file( $originalFile ) ) {
$fileCropped = Yii::app()->phpThumb->create($originalFile);
$fileCropped->crop($cropX,$cropY,$cropW,$cropH);
$fileCropped->save($file);
chmod( $file, 0777 );
}
//Overwrite the current thumb with the one from the already cropped image
if( is_file( $thumbFile ) ) {
$thumb=Yii::app()->phpThumb->create($file);
$thumb->resize(80,80);
$thumb->save($thumbFile);
}
echo $this->renderPartial('/postimage/_upload', array('model'=>$model->images, 'post_id'=>$model->id), true, false);
The script:
<script>
$('body').on('click', '#bt-crop', function(event){
var form = $('#crop-form');
var post = { };
form.find('input').each(function(){
var name = $(this).attr('name');
var value = $(this).val();
post[name] = value;
});
var opts = {
url: $(this).attr('href'),
data: post,
cache: false,
async: true,
type: 'POST',
success: function(data){
$('#upload-file-tmp').html(data);
//document.location.reload();
}
,error: function(e){
alert(e.responseText);
}
}
$.ajax(opts);
event.preventDefault();
});
</script>
The whole process works, except the thumb image isn’t refreshed and I don’t know why, I would really appreciate some help on this.
Thanks!