25 require_once dirname(__FILE__).
'/../../../../core/include/init.inc';
26 require_once dirname(__FILE__).
'/../../../../core/assets/files/image/image.inc';
28 if (empty($GLOBALS[
'SQ_SYSTEM']->user) || !($GLOBALS[
'SQ_SYSTEM']->user->canAccessBackend() || $GLOBALS[
'SQ_SYSTEM']->user->type() ==
'simple_edit_user')) {
29 echo return_javascript_error(
'You cannot upload file as a non-backend user');
34 if(!isset($_POST[
'token'])) {
35 trigger_error(
'Security token not found');
38 $token = get_unique_token();
39 if($_POST[
'token'] !== $token) {
40 trigger_error(
'Invalid secuirty token');
45 if (!isset($_FILES[
'create_image_upload'][
'name']) || !isset($_FILES[
'create_image_upload'][
'tmp_name']) || empty($_FILES[
'create_image_upload'][
'tmp_name']) || !isset($_FILES[
'create_image_upload'][
'error']) || !empty($_FILES[
'create_image_upload'][
'error'])) {
47 echo return_javascript_error(
'No file submitted');
49 }
else if (!isset($_POST[
'f_create_root_node'][
'assetid']) || empty($_POST[
'f_create_root_node'][
'assetid'])) {
51 echo return_javascript_error(
'No root node selected');
56 $am = $GLOBALS[
'SQ_SYSTEM']->am;
57 $root_node = $am->getAsset($_POST[
'f_create_root_node'][
'assetid']);
60 if (!is_null($root_node)) {
61 $new_image =
new Image();
64 $new_image->_tmp[
'uploading_file'] = TRUE;
65 $_FILES[
'create_image_upload'][
'filename'] = $_FILES[
'create_image_upload'][
'name'];
66 $_FILES[
'create_image_upload'][
'path'] = $_FILES[
'create_image_upload'][
'tmp_name'];
69 $invalid_file_type = $new_image->validFile($_FILES[
'create_image_upload']);
70 if (!$invalid_file_type) {
71 echo return_upload_error(
'File extension not allowed. [CORE0106]');
76 $new_image->setAttrValue(
'name', $_FILES[
'create_image_upload'][
'name']);
77 $new_image->saveAttributes();
79 'asset' => $root_node,
80 'link_type' => SQ_LINK_TYPE_1,
84 $successful = $new_image->create($link, $_FILES[
'create_image_upload']);
90 <script type=
"text/javascript">
91 top.frames[
'sq_wysiwyg_popup_main'].toggleCreateImage();
92 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'sq_asset_finder_f_imageid_assetid').value =
"<?php echo $new_image->id; ?>";
93 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'sq_asset_finder_f_imageid_label').value =
"<?php echo $new_image->short_name; ?>";
94 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'f_imageid[assetid]').value =
"<?php echo $new_image->id; ?>";
95 top.frames[
'sq_wysiwyg_popup_main'].setImageInfo();
101 $success_return = ob_get_contents();
104 echo $success_return;
107 echo return_upload_error(
'Unable to create file, web path already exists[CORE0086] or file is infected[CORE0300]');
111 echo return_upload_error(
'Invalid root node');
116 echo return_upload_error(
'Could not create image asset');
125 function return_javascript_error($error=
'') {
127 if (!empty($error)) {
131 <script type=
"text/javascript">
132 alert(
'<?php echo $error; ?>');
138 $return_code = ob_get_contents();
153 function return_upload_error($error=
'') {
156 $error =
'Service unavailable, could not upload image';
161 <script type=
"text/javascript">
162 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'show_upload_error').style.display =
"block";
163 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'show_upload_error').style.visibility =
"visible";
164 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'show_upload_error').innerHTML =
"<?php echo $error ?>";
170 $return_code = ob_get_contents();