/** * installs an uploaded template */ function _performUploadTemplate() { // handle the uploaded file $files = HttpVars::getFiles(); $uploads = new FileUploads($files); if (count($files) == 0 || $files["templateFile"]["name"] == "") { $this->_view = new AdminTemplatedView($this->_blogInfo, "newglobaltemplate"); $this->_view->setValue("templateFolder", TemplateSetStorage::getBaseTemplateFolder()); $this->_view->setErrorMessage($this->_locale->tr("error_must_upload_file")); $this->setCommonData(); return false; } $config =& Config::getConfig(); $tmpFolder = $config->getValue('temp_folder'); // move it to the temporary folder $result = $uploads->process($tmpFolder); // and from there, unpack it $upload = new FileUpload($files['templateFile']); $templateSandbox = new TemplateSandbox(); $valid = $templateSandbox->checkTemplateSet($upload->getFileName(), $tmpFolder . '/'); if ($valid < 0) { $this->_view = new AdminSiteTemplatesListView($this->_blogInfo); $this->_view->setErrorMessage($this->_checkTemplateSandboxResult($valid)); $this->setCommonData(); return false; } // the template was ok, so then we can proceed and move it to the main // template folder, add it to our array of templates // // :KLUDGE: // // maybe we should simply move the files rather than unpacking the whole // thing again, but this indeed makes things easier! ;) $unpacker = new Unpacker(); $templateFolder = $config->getValue('template_folder'); $fileToUnpack = $tmpFolder . '/' . $upload->getFileName(); if (!$unpacker->unpack($fileToUnpack, $templateFolder)) { $this->_view = new AdminSiteTemplatesListView($this->_blogInfo); $tf = new Textfilter(); $this->_view->setErrorMessage($this->_locale->pr('error_installing_template', $tf->filterAllHtml($upload->getFileName()))); $this->setCommonData(); return false; } // if the template set was installed ok in the template folder, we can record // it as a valid set $ts = new TemplateSetStorage(); $fileParts = explode(".", $upload->getFileName()); $templateName = $fileParts[0]; $ts->addTemplate($templateName); $this->_view = new AdminSiteTemplatesListView($this->_blogInfo); $this->_view->setSuccessMessage($this->_locale->pr('template_installed_ok', $templateName)); $this->setCommonData(); return true; }
function perform() { // uploads the file and moves it to the correct folder $uploads = new FileUploads($this->_files); // make sure were it should go $ts = new TemplateSetStorage(); $blogId = $this->_blogInfo->getId(); $destFolder = $ts->getTemplateFolder($this->_templateId, $blogId); if (!empty($this->_subFolderId)) { $destFolder = $destFolder . $this->_subFolderId . "/"; } // and move it there $processedUploads = $uploads->process($destFolder); // check for the different error conditions we can have if ($processedUploads == FILE_UPLOADS_NOT_ENABLED) { if (empty($this->_subFolderId)) { $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId); } else { $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId); } $this->_view->setErrorMessage($this->_locale->tr("error_uploads_disabled")); $this->setCommonData(); return false; } $fileResult = $processedUploads[0]; if ($fileResult->getError()) { if (empty($this->_subFolderId)) { $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId); } else { $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId); } $this->_view->setErrorMessage($this->_locale->tr("error_adding_template_file")); $this->setCommonData(); return false; } if (empty($this->_subFolderId)) { $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId); } else { $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId); } $this->_view->setSuccessMessage($this->_locale->pr("template_file_added_ok", $this->_templateId)); $this->setCommonData(); return true; }
public function loadAuthorized($attributes) { $model = FileUploads::model()->findByAttributes($attributes); if ($model === null) { if (Yii::app()->request->isAjaxRequest) { header("HTTP/1.0 404 Not Found"); echo 'You are not authorized to perform this action.'; exit; } else { throw new CHttpException(404, 'You are not authorized to perform this action.'); } } return $model; }
function _performUploadLocale() { // since we are here, the file name was validated to be ok, so we can // continue with the operation $files = HttpVars::getFiles(); $uploads = new FileUploads($files); $this->_view = new AdminSiteLocalesListView($this->_blogInfo); // we can first of all move the file to the destionation folder $result = $uploads->process($this->_config->getValue("locale_folder")); // the only thing that can happen is that the file was not correctly saved if ($result[0]->getError() != 0) { $this->_view->setErrorMessage($this->_locale->tr("error_saving_locale")); return false; } // and once it's there, we can do as if we were adding a locale code $upload = new FileUpload($files["localeFile"]); $res = preg_match(REGEXP_VALID_LOCALE, $upload->getFileName(), $matches); $localeCode = $matches[1]; // add the file to the list of locales $locales = new Locales(); $locales->addLocale($localeCode); $this->_view->setSuccessMessage($this->_locale->pr("locale_added_ok", $localeCode)); return true; }
function upload_process($type_id = '0') { $attach_info = array(); //init moved here if (empty($this->upload_dir)) { $this->upload_dir = gmdate("Y") . DS . gmdate("m") . DS . gmdate("d"); } $this->out_file_path = PHPB2B_ROOT . $this->attachment_dir . DS . $this->upload_dir . DS; $this->upload_url = str_replace(array(DS, "\\", "\\'"), "/", $this->upload_dir) . '/'; if (isset($_FILES) && $_FILES[$this->upload_form_field]['size'] > 0) { $mimetype = new mimetype(); $file_ext = strtolower(fileext($_FILES[$this->upload_form_field]['name'])); if ($this->is_image) { //check image format if (!in_array($file_ext, $this->imgext)) { return L("format_not_support"); } } if (in_array($file_ext, $this->imgext)) { $this->is_image = 1; $this->allowed_file_ext = $this->imgext; if (!in_array($_FILES[$this->upload_form_field]['type'], $mimetype->image_mimes)) { flash("format_not_support", '', 0); } } require LIB_PATH . "upload.class.php"; $upload = new FileUploads(); $upload->upload_dir = $this->out_file_path; $upload->extensions = $this->allowed_file_ext; $upload->max_file_size = $this->max_file_size; $upload->the_temp_file = $_FILES[$this->upload_form_field]['tmp_name']; $upload->the_file = $_FILES[$this->upload_form_field]['name']; $upload->http_error = $_FILES[$this->upload_form_field]['error']; if ($_FILES[$this->upload_form_field]['size'] > $this->max_file_size) { flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext)); } $isuploaded = $upload->upload($this->rename_file); if (!$isuploaded) { flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext)); } //insert into db. //$_this = & Attachments::getInstance(); $_this = Attachments::getInstance(); $this->file_full_url = $this->upload_url . $upload->file_copy; $this->file_size = $_FILES[$this->upload_form_field]['size']; $this->out_file_name = $upload->file_copy; $this->out_file_full_path = $this->out_file_path . $this->out_file_name; if ($this->is_image) { list($width, $height) = @getimagesize($this->out_file_full_path); $this->width = intval($width); $this->height = intval($height); if ($this->if_orignal) { copy($this->out_file_full_path, $this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension); } if ($this->if_thumb) { require LIB_PATH . "thumb.class.php"; if ($this->if_orignal) { $img = new Image($this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension, $this->out_file_full_path); } else { $img = new Image($this->out_file_path . $this->rename_file . $upload->file_extension, $this->out_file_full_path); } if ($this->if_thumb_middle) { list($width, $height) = $this->getScale("middle"); $img->Thumb($width, $height, '.middle.jpg'); } list($width, $height) = $this->getScale("small"); $img->Thumb($width, $height); } if ($this->if_watermark) { $markimg = new ImageWatermark($file_name = $this->out_file_path . $this->rename_file . $upload->file_extension); $markimg->fontFile = DATA_PATH . "fonts/" . $this->fontFace; if ($this->is_water_image) { $markimg->appendImageMark(PHPB2B_ROOT . STATICURL . 'images/watermark.png'); } else { $waterText = !empty($this->is_water_text) ? $this->is_water_text : pb_getenv('HTTP_HOST'); $markimg->color = !empty($this->water_text_color) ? $this->water_text_color : '#FF0000'; $markimg->angle = 0; //rotate for textwatermark. $markimg->appendTextMark($waterText); } if ($this->width > 150 || $this->height > 150) { $markimg->write($file_name); } } if ($this->if_thumb_large) { list($width, $height) = $this->getScale("large"); $img->Thumb($width, $height, null); } } //save if ($this->insert_new) { $attach_info['attachment'] = $this->file_full_url; $attach_info['created'] = $attach_info['modified'] = $_this->timestamp; $attach_info['title'] = empty($this->title) ? reset(explode(".", $upload->the_file)) : $this->title; $attach_info['description'] = $this->description; $attach_info['file_name'] = $upload->the_file; $attach_info['file_name'] = $this->is_image; $attach_info['file_size'] = $_FILES[$this->upload_form_field]['size']; $attach_info['file_type'] = $_FILES[$this->upload_form_field]['type']; $attach_info['attachmenttype_id'] = $type_id; if (!empty($GLOBALS['pb_user'])) { $attach_info['member_id'] = intval($GLOBALS['pb_user']['pb_userid']); } $this->id = $_this->Add($attach_info); } } }
function upload_process($type_id = '0') { $attach_info = array(); if (isset($_FILES) && $_FILES[$this->upload_form_field]['size'] > 0) { $mimetype = new mimetype(); if (in_array($file_ext = fileext($_FILES[$this->upload_form_field]['name']), $this->imgext)) { $this->is_image = 1; $this->allowed_file_ext = $this->imgext; if (!in_array($_FILES[$this->upload_form_field]['type'], $mimetype->image_mimes)) { flash("format_not_support", '', 0); } } require LIB_PATH . "upload.class.php"; $upload = new FileUploads(); $upload->upload_dir = $this->out_file_path; $upload->extensions = $this->allowed_file_ext; $upload->max_file_size = $this->max_file_size; $upload->the_temp_file = $_FILES[$this->upload_form_field]['tmp_name']; $upload->the_file = $_FILES[$this->upload_form_field]['name']; $upload->http_error = $_FILES[$this->upload_form_field]['error']; if ($_FILES[$this->upload_form_field]['size'] > $this->max_file_size) { flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext)); } $isuploaded = $upload->upload($this->rename_file); if (!$isuploaded) { flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext)); } //insert into db. $_this =& Attachments::getInstance(); $this->file_full_url = $this->upload_url . $upload->file_copy; $this->file_size = $_FILES[$this->upload_form_field]['size']; $this->out_file_name = $upload->file_copy; $this->out_file_full_path = $this->out_file_path . $this->out_file_name; $this->file_name = $upload->the_file; if ($this->is_image) { list($width, $height) = @getimagesize($this->out_file_full_path); $this->width = intval($width); $this->height = intval($height); if ($this->if_orignal) { copy($this->out_file_full_path, $this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension); } if ($this->if_thumb) { require LIB_PATH . "thumb.class.php"; if ($this->if_orignal) { $img = new Image($this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension, $this->out_file_full_path); } else { $img = new Image($this->out_file_path . $this->rename_file . $upload->file_extension, $this->out_file_full_path); } if ($this->if_thumb_middle) { list($width, $height) = $this->getScale("middle"); $img->Thumb($width, $height, '.middle.jpg'); } list($width, $height) = $this->getScale("small"); $img->Thumb($width, $height); } if ($this->if_watermark) { $markimg = new ImageWatermark($file_name = $this->out_file_path . $this->rename_file . $upload->file_extension); $markimg->fontFile = APP_ROOT . "data/fonts/" . $this->fontFace; if ($this->is_water_image) { $markimg->appendImageMark(APP_ROOT . 'images/watermark.png'); } else { $waterText = !empty($this->is_water_text) ? $this->is_water_text : URL; $markimg->color = !empty($this->water_text_color) ? $this->water_text_color : '#FF0000'; $markimg->angle = 45; $markimg->appendTextMark($waterText); } if ($this->width > 150 || $this->height > 150) { $markimg->write($file_name); } } if ($this->if_thumb_large) { list($width, $height) = $this->getScale("large"); $img->Thumb($width, $height, null); } } //save if ($this->insert_new) { $attach_info['attachment'] = $this->file_full_url; $attach_info['created'] = $attach_info['modified'] = $_this->timestamp; $attach_info['title'] = empty($this->title) ? reset(explode(".", $upload->the_file)) : $this->title; $attach_info['description'] = $this->description; $attach_info['file_name'] = $upload->the_file; $attach_info['is_image'] = $this->is_image; $attach_info['file_size'] = $_FILES[$this->upload_form_field]['size']; $attach_info['file_type'] = $_FILES[$this->upload_form_field]['type']; $attach_info['attachmenttype_id'] = $type_id; if (isset($_SESSION['MemberID'])) { $attach_info['member_id'] = intval($_SESSION['MemberID']); } $this->id = $_this->Add($attach_info); } } }
/** * stores a new resource in disk * * @param ownerId The id of the owner of this file * @param albumId The album id to which the * @param upload a FileUpload object with information about the * uploaded file */ function storeUpload($resourceId, $ownerId, $upload) { // check that the folders exist if (!$this->_checkBaseStorageFolder()) { return false; } if (!$this->_checkUserStorageFolder($ownerId)) { return false; } // new name for the file $fileParts = explode(".", $upload->getFileName()); $fileExt = $fileParts[count($fileParts) - 1]; $fileName = "{$ownerId}-{$resourceId}.{$fileExt}"; $filePath = $this->getUserFolder($ownerId); // move the file to the temporaray folder first $config =& Config::getConfig(); $tmpFolder = $config->getValue("temp_folder"); /*$files = HttpVars::getFiles();*/ // we don't need the parameter in the constructor though it is necessary // according to the signature of the method $uploads = new FileUploads(null); $result = $uploads->processFile($upload, $tmpFolder); if ($result < 0) { return $result; } // rename it while it's there $origFile = $tmpFolder . "/" . basename($upload->getTmpName()); //do not use storeFile method because I have change filename in $tmpFolder. //$destFile = $this->storeFile( $resourceId, $ownerId, $origFile, RESOURCE_STORAGE_STORE_MOVE ); //$destFile use $filePath and $fileName generated above. $destFile = $filePath . $fileName; //========================================= //codes below are copy and modify from method storeFile // first of all, check if the file is readable and if not, quit if (!File::isReadable($origFile)) { return false; } $res = File::rename($origFile, $destFile); if (!$res) { return false; } // check that the permissions are correct File::chMod($destFile, 0755); //========================================= return $destFile; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = FileUploads::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
function _performUploadTemplate() { // get the temporary folder $config =& Config::getConfig(); $tmpFolder = $config->getValue("temp_folder"); // move it to the temporary folder $files = HttpVars::getFiles(); if (count($files) == 0 || $files["templateFile"]["name"] == "") { $this->_view = new AdminTemplatedView($this->_blogInfo, "newblogtemplate"); $this->_view->setValue("templateFolder", TemplateSetStorage::getBlogBaseTemplateFolder($this->_blogInfo->getId())); $this->_view->setErrorMessage($this->_locale->tr("error_must_upload_file")); $this->setCommonData(); return false; } $uploads = new FileUploads($files); $result = $uploads->process($tmpFolder); if ($result < 0) { $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_uploads_disabled")); $this->setCommonData(); return false; } $upload = new FileUpload($files["templateFile"]); // and make it go through the template sandbox to check if // we're dealing with a 'healthy' file $templateSandbox = new TemplateSandbox(); $valid = $templateSandbox->checkTemplateSet($upload->getFileName(), $tmpFolder . "/"); if ($valid < 0) { $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo); $this->_view->setErrorMessage(AdminAddTemplateAction::_checkTemplateSandboxResult($valid)); $this->setCommonData(); return false; } // // :KLUDGE: // // maybe we should simply move the files rather than unpacking the whole // thing again, but this indeed makes things easier! ;) // // since it is a local template, the path has to be $template_folder/blog_x/$templateName $ts = new TemplateSetStorage(); $blogTemplateFolder = $ts->createBlogTemplateFolder($this->_blogInfo->getId()); // it should be there now... we can continue $destFolder = $blogTemplateFolder . "/"; $unpacker = new Unpacker(); if (!$unpacker->unpack($tmpFolder . "/" . $upload->getFileName(), $destFolder)) { $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_installing_template")); $this->setCommonData(); // remove the file before returning! File::delete($tmpFolder . "/" . $upload->getFileName()); return false; } // if the template set was installed ok in the template folder, we can record // it as a valid set $fileParts = explode(".", $upload->getFileName()); $templateName = $fileParts[0]; $ts->addTemplate($templateName, $this->_blogInfo->getId()); // remove the file File::delete($tmpFolder . "/" . $upload->getFileName()); $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo); $this->_view->setSuccessMessage($this->_locale->pr("template_installed_ok", $templateName)); $this->setCommonData(); return true; }