예제 #1
0
function updatePreview($file_id, $resource)
{
    $objResponse =& new xajaxResponse();
    $CFile = new CFile($file_id);
    $path_file = $CFile->path . 'sm_' . $CFile->name;
    if ($CFile->image_size['height'] > portfolio::PREVIEW_MAX_HEIGHT || $CFile->image_size['width'] > portfolio::PREVIEW_MAX_WIDTH) {
        $CFile = $CFile->resizeImage($path_file, portfolio::PREVIEW_MAX_WIDTH, portfolio::PREVIEW_MAX_HEIGHT, 'auto', true);
    } else {
        $CFile = uploader::remoteCopy($CFile->id, $CFile->table, $CFile->path, false, 'sm_f_');
    }
    uploader::sclear($resource);
    // Чистим заменяем
    uploader::screateFile($CFile, $resource);
    $callback = uploader::getCallback(uploader::sgetTypeUpload($resource));
    $template = uploader::getTemplate('uploader.file', 'portfolio/');
    $template = str_replace(array('{idFile}', '{fileName}'), array($CFile->id, $CFile->original_name), $template);
    $objResponse->script("\n        \$\$('#work_preview_file .qq-upload-list').set('html', '{$template}');\n        \$\$('#work_preview_file .qq-upload-list .qq-upload-file').set('href', '" . WDCPREFIX . "/{$path_file}');\n        \$\$('#work_preview_file .qq-upload-list .qq-uploader-fileID').show();\n    ");
    $objResponse->script("\n        \$\$('#work_preview_file .qq-upload-delete').addEvent('click', function() {\n            new Request.JSON({\n                url: '/uploader.php',\n                onSuccess: function(resp) {\n                    if(resp.success) {\n                        \$\$('#work_preview_file .qq-upload-list').set('html', '');\n                        if(resp.onComplete !== undefined) {\n                            eval(resp.onComplete);\n                        }\n                    }  \n                }\n            }).post({\n                'action': 'remove',\n                'files' : [{$CFile->id}],\n                'resource': '{$resource}',\n                'u_token_key': '{$_SESSION['rand']}'\n            });\n        });\n    ");
    $objResponse->script($callback);
    return $objResponse;
}