public function actionPost() { $model = new PostResumeForm(Yii::app()->user->id); //check max job post if ($model->getCountUserJobs() < Yii::app()->params['maxResumeJobTitles']) { if (isset($_POST['PostResumeForm'])) { $model->attributes = $_POST['PostResumeForm']; $model->resumeFile = CUploadedFile::getInstance($model, 'resumeFile'); $model->portfolioFile = CUploadedFile::getInstance($model, 'portfolioFile'); if ($model->validate()) { //checks the number of job titles submitted are within the limit boundry if (count($model->jobTitles) + $model->getCountUserJobs() > Yii::app()->params['maxResumeJobTitles']) { Yii::app()->user->setFlash('warning', sprintf(Yii::t('app', 'msg.warning.max_job_titles_exceed'), Yii::app()->params['maxResumeJobTitles'])); $this->redirect(Yii::app()->createAbsoluteUrl($this->getModule()->returnUrl)); Yii::app()->end(); return; } $extension = FileHelper::getExtension($model->resumeFile->name); if (!empty($model->portfolioFile->name)) { $extension_PortFolio = FileHelper::getExtension($model->portfolioFile->name); } else { $extension_PortFolio = ""; } //saved file name in the following pattern // {user_id}cv{time_stamp_string}.{extension} $fileName = Yii::app()->user->id . 'cv' . Yii::app()->dateFormatter->format('yyyy-MM-dd_H-mm-ss', time()) . '.' . $extension; if (!empty($extension_PortFolio)) { $fileName_PortFolio = Yii::app()->user->id . 'pf' . Yii::app()->dateFormatter->format('yyyy-MM-dd_H-mm-ss', time()) . '.' . $extension_PortFolio; } else { $fileName_PortFolio = ""; } if ($model->save(Yii::app()->user->id, $fileName, $fileName_PortFolio)) { //if(!empty($fileName_PortFolio)) //{ $userFilePath = FileHelper::getFilePath(Yii::getPathOfAlias('site.files') . '/resumes/' . Yii::app()->user->id . '/'); $model->resumeFile->saveAs($userFilePath . $fileName); if (!empty($fileName_PortFolio)) { $model->portfolioFile->saveAs($userFilePath . $fileName_PortFolio); } Yii::app()->user->setFlash('success', Yii::t('app', 'msg.success.post_resume')); //} } //checks the number of job titles submitted are within the limit boundry if (count($model->jobTitles) + $model->getCountUserJobs() > Yii::app()->params['maxResumeJobTitles']) { $this->refresh(true); } else { $this->redirect($this->createAbsoluteUrl('index')); } } } $this->render('post', array('model' => $model)); } else { Yii::app()->user->setFlash('warning', sprintf(Yii::t('app', 'msg.warning.max_job_titles_exceed'), Yii::app()->params['maxResumeJobTitles'])); $this->redirect(Yii::app()->createAbsoluteUrl($this->getModule()->returnUrl)); } }
public static function resizeDown($image, $width, $height) { if (substr($image, 0, 1) == '/' || ini_get('allow_url_fopen')) { if (substr($image, 0, 1) == '/') { $sourcePath = Yii::getPathOfAlias('webroot') . $image; } else { $sourcePath = $image; } $extension = FileHelper::getExtension($sourcePath); $filename = pathinfo($sourcePath, PATHINFO_FILENAME); $resizeUrl = '/files/.resized/' . $filename . '_' . substr(md5($sourcePath), 0, 8) . '_' . $width . 'x' . $height . '.' . $extension; $resizePath = Yii::getPathOfAlias('webroot') . $resizeUrl; if (!is_dir(dirname($resizePath))) { mkdir(dirname($resizePath)); @chmod(dirname($resizePath), 0777); } Yii::import('application.vendors.wideimage.WideImage', true); WideImage::load($sourcePath)->resizeDown($width, $height)->saveToFile($resizePath); $image = $resizeUrl; } return $image; }
<tr> <th><?php echo CHtml::activeLabel($product, 'image_path'); ?> </th> <td> <?php echo CHtml::activeFileField($product, 'productFile'); ?> <?php if ($product->image_path) { ?> <br /> <?php if (FileHelper::getExtension($product->image_path) == 'swf') { ?> <?php echo CHtml::link($product->getProductFileUrl(), $product->getProductFileUrl(), array('target' => '_blank')); ?> <?php } else { ?> <?php echo CHtml::image($product->getProductFileUrl(), '', array('style' => 'width:300px;')); ?> <?php } ?> <br /> <?php
/** * _populateFilesVariable * @description Reads the configured folder and populates the array with filenames. * @author Henrik Hussfelt * @since 1.0 */ private function _populateFilesVariable() { // Get config $filesConfig = $this->getSetting('files'); // Create files array $files = array(); // Check if folder is found and set to handle if ($handle = opendir($filesConfig['start_path'])) { // Start file-counter, so that we have a path to move to and use in XML file $x = 0; // Loop through all files while (false !== ($file = readdir($handle))) { // But skip any files that begin with . if (substr($file, 0, 1) != ".") { // Prepare content name for Alfresco XML file $content_name = "content" . $x . "." . FileHelper::getExtension($file); // Create array $fileArr = array('name' => $file, 'content_name' => $content_name); // Add to array array_push($files, $fileArr); // Add one to counter $x += 1; } } // Set the main varable $this->_files = $files; // Close the directory closedir($handle); } // If there where no files, kill app if (count($this->_files) == 0) { die('No files in folder: ' . $filesConfig['start_path'] . ' Nothing to do. Goodbye!'); } }
?> <?php $basicContent = ob_get_clean(); ?> <?php $tabs = array('基本资料' => $basicContent); ?> <?php foreach (I18nHelper::getFrontendLanguages() as $lang => $attr) { ?> <?php ob_start(); ?> <?php $this->widget('zii.widgets.CDetailView', array('htmlOptions' => array('class' => 'form'), 'data' => $banner, 'attributes' => array(array('name' => 'title', 'value' => $banner->i18nFormData['title_' . $lang]), array('name' => 'banner_path', 'value' => CHtml::image(Helper::mediaUrl(Banner::UPLOAD_THUMBNAIL_IMAGE_PATH . $banner->i18nFormData['banner_path_' . $lang])), 'type' => 'html', 'visible' => strlen($banner->i18nFormData['banner_path_' . $lang]) > 0 && in_array(FileHelper::getExtension($banner->i18nFormData['banner_path_' . $lang]), array('jpg', 'jpeg', 'gif', 'png'))), array('name' => 'banner_path', 'value' => CHtml::link($banner->i18nFormData['banner_path_' . $lang], Helper::mediaUrl(Banner::UPLOAD_THUMBNAIL_IMAGE_PATH . $banner->i18nFormData['banner_path_' . $lang])), 'type' => 'html', 'visible' => strlen(Banner::UPLOAD_THUMBNAIL_IMAGE_PATH . $banner->i18nFormData['banner_path_' . $lang]) > 0 && in_array(FileHelper::getExtension(Banner::UPLOAD_THUMBNAIL_IMAGE_PATH . $banner->i18nFormData['banner_path_' . $lang]), array('jpg', 'jpeg', 'gif', 'png')) == false), array('name' => 'is_released', 'value' => $banner->i18nFormData['is_released_' . $lang] ? '是' : '否')))); ?> <?php $i18nContent = ob_get_clean(); ?> <?php $tabs += array($attr['label'] => $i18nContent); ?> <?php } ?> <?php $this->widget('zii.widgets.jui.CJuiTabs', array('tabs' => $tabs)); ?>
<tr> <th><?php echo CHtml::activeLabel($model, 'banner_path'); ?> </th> <td> <?php echo CHtml::activeFileField($model, 'bannerFile'); ?> <?php if ($model->banner_path) { ?> <br /> <?php if (FileHelper::getExtension($model->banner_path) == 'swf') { ?> <?php echo CHtml::link($model->getLargeUrl(), $model->getBannerUrl(), array('target' => '_blank')); ?> <?php } else { ?> <?php echo CHtml::image($model->getLargeUrl()); ?> <?php } ?> <br /> <?php
<tr> <th><?php echo CHtml::activeLabel($brand, 'image_path'); ?> </th> <td> <?php echo CHtml::activeFileField($brand, 'brandFile'); ?> <?php if ($brand->image_path) { ?> <br /> <?php if (FileHelper::getExtension($brand->image_path) == 'swf') { ?> <?php echo CHtml::link($brand->getThumbFileUrl(), $brand->getThumbFileUrl(), array('target' => '_blank')); ?> <?php } else { ?> <?php echo CHtml::image($brand->getThumbFileUrl(), '', array('style' => 'width:300px;')); ?> <?php } ?> <br /> <?php
<tr> <th><?php echo CHtml::activeLabel($server, 'image_path'); ?> </th> <td> <?php echo CHtml::activeFileField($server, 'serverFile'); ?> <?php if ($server->image_path) { ?> <br /> <?php if (FileHelper::getExtension($server->image_path) == 'swf') { ?> <?php echo CHtml::link($server->getServerFileUrl(), $server->getServerFileUrl(), array('target' => '_blank')); ?> <?php } else { ?> <?php echo CHtml::image($server->getServerFileUrl(), '', array('style' => 'width:300px;')); ?> <?php } ?> <br /> <?php