/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Photo(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Photo'])) { $model->attributes = $_POST['Photo']; if (isset($_FILES['images']['name'][0]) && $_FILES['images']['name'][0] !== '') { $model->name = 'new'; } if ($model->validate()) { $images = CUploadedFile::getInstancesByName('images'); foreach ($images as $image) { $imageModel = new Photo(); $name = uniqid() . $image->name; $image->saveAs(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name); copy(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name, Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name); $thumb = Yii::app()->image->load(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name); $thumb->resize(300, 300); $thumb->save(); $imageModel->name = $name; $imageModel->category_id = $_POST['Photo']['category_id']; $imageModel->save(); } Yii::app()->user->setFlash('success', Yii::t('main', 'Данные успешно сохранены!')); $this->refresh(); } else { Yii::app()->user->setFlash('error', Yii::t('main', 'Ошибка!')); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new gRecruitment(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['gRecruitment'])) { $model->attributes = $_POST['gRecruitment']; $model->followup_id = 1; $model->final_result_id = 1; $model->image = CUploadedFile::getInstance($model, 'image'); $docs = CUploadedFile::getInstancesByName('docs'); if (isset($model->image)) { $model->photo_path = $model->image->name; } if ($model->save()) { if (isset($model->image)) { $model->image->saveAs(Yii::app()->basePath . '/../images/recruitment/' . $model->image->name); } if (isset($docs)) { mkdir(Yii::getPathOfAlias('webroot') . '/images/recruitment/' . $model->id); //chmod(Yii::getPathOfAlias('webroot').'/images/recruitment/'.$model->id, 0755); foreach ($docs as $image => $pic) { $pic->saveAs(Yii::app()->basePath . '/../images/recruitment/' . $model->id . '/' . $pic->name); } } $this->redirect(array('/m1/gRecruitment')); } } $this->render('create', array('model' => $model)); }
public static function saves($typeModel, $idModel, $files_field_name = 'upload', $need_file_name = '') { $Uploads = CUploadedFile::getInstancesByName($files_field_name); if (is_null($Uploads)) { return false; } $folder = self::makePath($typeModel, $idModel); if (!file_exists($folder)) { mkdir($folder, 0777, true); } $arNames = array(); foreach ($Uploads as $Upload) { if ($need_file_name == '') { $newName = str_replace('.' . $Upload->getExtensionName(), '', urlencode($Upload->getName())) . "-" . date("YmdHis", time()) . '.' . $Upload->getExtensionName(); } else { //добавка для сохранения кадров под конкретным именем $newName = $need_file_name; } $newPath = $folder . self::DS . $newName; if ($Upload->saveAs($newPath)) { if (file_exists($newPath)) { $arNames[] = $newName; } else { return false; } } else { return false; } } return $arNames; }
/** * edit a particular model. */ public function actionEdit() { $this->layout = '//layouts/notitle_main'; $infoType = $this->getInfoType(); $basicModelName = ucfirst(strtolower($infoType)) . 'InfoView'; $isPageDirty = 0; $actionType = 'view'; if (!empty($_GET['action'])) { $actionType = $_GET['action']; } list($productId, $model, $customInfo, $customFieldArr) = InfoService::initInfoPage($infoType, $this, $actionType, Yii::app()->request); if (!Info::isProductAccessable($productId)) { throw new CHttpException(400, Yii::t('Common', 'Required URL not found or permission denied.')); } if (isset($_POST[$basicModelName])) { if ('' == $_POST['templateTitle'] && empty($_POST['isPageDirty']) && !empty($model->id) && $this->isEditAction($actionType)) { $this->redirect(array('edit', 'type' => $infoType, 'id' => $model->id)); } else { $attachmentFile = CUploadedFile::getInstancesByName('attachment_file'); list($model, $customFieldArr) = InfoService::saveInfoPage($infoType, $model, $customInfo, $attachmentFile, $this, $actionType, Yii::app()->request); $isPageDirty = 1; } } $buttonList = InfoService::getButtonList($infoType, $actionType, $model); $this->render('edit', array('infoType' => $infoType, 'isPageDirty' => $isPageDirty, 'actionType' => $actionType, 'model' => $model, 'buttonList' => $buttonList, 'customfield' => $customFieldArr)); }
/** * Displays the contact page */ public function actionContact() { $model = new ContactForm(); if (isset($_POST['ContactForm'])) { $model->attributes = $_POST['ContactForm']; if ($model->validate()) { //$attachment = Yii::app()->baseUrl.'/images/ban_admin.JPG'; $images = CUploadedFile::getInstancesByName('images'); $attachement = Yii::getPathOfAlias('webroot.files') . $model->file; $mail = Yii::app()->Smtpmail; $mail->SetFrom('*****@*****.**', $model->name); $mail->Subject = $model->subject; $msg = $model->body . '<br />' . $model->email . '<br/>' . $model->name; $mail->MsgHTML($msg); $mail->CharSet = "UTF-8"; $mail->AddAddress('*****@*****.**', "CADS Programmer"); $mail->AddAddress($model->email, "CADS Programmer"); $mail->AddAttachment($attachement); if (!$mail->Send()) { Yii::app()->user->setFlash('error', 'Error while sending email: ' . $mail->getError()); } Yii::app()->user->setFlash('contact', 'You Email have been Sent'); $this->refresh(); } } $this->render('contact', array('model' => $model)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Post'])) { $_POST['Post']['images'] = $model->images; $_POST['Post']['author_id'] = $model->author_id; $model->attributes = $_POST['Post']; $images = CUploadedFile::getInstancesByName('images'); if (isset($images) && count($images) > 0) { $pic_names = array(); foreach ($images as $image => $pic) { $sourcePath = pathinfo($pic->getName()); $pic_name = time() . '-' . ++$image . '-' . $model->author_id . '.' . $sourcePath['extension']; $path = Yii::getPathOfAlias('webroot') . "/images/"; if ($pic->saveAs($path . $pic_name)) { $pic_names[] = $pic_name; } } $model->images = implode(",", $pic_names); } if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model)); }
public function actionIndex($is_product = 1) { if (!empty($_POST)) { $is_new_product = $is_product; $images = CUploadedFile::getInstancesByName('images'); if (isset($images) && count($images) > 0) { // go through each uploaded image foreach ($images as $image => $pic) { $model = new Slides(); $imageType = explode('.', $pic->name); $imageType = $imageType[count($imageType) - 1]; $imageName = md5(uniqid()) . '.' . $imageType; if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName)) { $model->image = $imageName; $model->name = $pic->name; $model->is_product = $is_new_product; $model->save(); Yii::app()->user->setFlash('success', translate('Thêm thành công.')); } // handle the errors here, if you want } } PIUrl::createUrl('/admin/slides/index', array('is_product' => $is_product)); } $criteria = new CDbCriteria(); $criteria->addCondition("is_product= {$is_product}"); $criteria->order = 'id DESC'; $count = Slides::model()->count($criteria); $pages = new CPagination($count); // results per page $pages->pageSize = 6; $pages->applyLimit($criteria); $model = Slides::model()->findAll($criteria); $this->render('index', compact('model', 'pages')); }
/** * Action which handles file uploads * * The result is an json array of all uploaded files. */ public function actionUpload() { $files = array(); foreach (CUploadedFile::getInstancesByName('files') as $cFile) { $files[] = $this->handleFileUpload($cFile); } return $this->renderJson(array('files' => $files)); }
public function getuppload_files() { if (!$this->isimport) { return CUploadedFile::getInstancesByName(''); } else { return array(123, 321); } }
public function updateProductImages(Product $product) { foreach (CUploadedFile::getInstancesByName('ProductImage') as $key => $image) { $productImage = new ProductImage(); $productImage->product_id = $product->id; $productImage->attributes = $_POST['ProductImage'][$key]; $productImage->addFileInstanceName('ProductImage[' . $key . '][name]'); $productImage->save(); } }
/** * @depends testGetInstancesByName * * @see https://github.com/yiisoft/yii/issues/159 */ public function testGetInstancesByNamePartOfOtherName() { $baseInputName = 'base_name'; $tailedInputName = $baseInputName . '_tail'; $_FILES[$baseInputName] = array('name' => $baseInputName . '.dat', 'type' => 'somemime/' . $baseInputName, 'tmp_name' => '/tmp/' . $baseInputName, 'error' => UPLOAD_ERR_OK, 'size' => 100); $_FILES[$tailedInputName] = array('name' => $tailedInputName . '.dat', 'type' => 'somemime/' . $tailedInputName, 'tmp_name' => '/tmp/' . $tailedInputName, 'error' => UPLOAD_ERR_OK, 'size' => 100); $uploadedFiles = CUploadedFile::getInstancesByName($baseInputName); foreach ($uploadedFiles as $uploadedFile) { $this->assertEquals($_FILES[$baseInputName]['name'], $uploadedFile->getName(), 'Wrong file fetched!'); } }
public function actionUpload($recordType, $id, $InstanceName, $fileType = "File", $filePath = "", $fileExtName = "", $newResizeWidth = 1600, $newResizeHeight = 1280) { if (isset($recordType) && isset($id)) { $uploadedFiles = CUploadedFile::getInstancesByName($InstanceName); $modelName = $fileType; if (empty($filePath)) { $fileParam = $fileType == 'File' ? 'filePath' : 'imgPath'; $filePath = Yii::app()->params[$fileParam] . '/' . $recordType . '/' . $id . '/'; } Yii::app()->file->set($filePath)->createDir(0777); $uploadedFilesIds = array(); if ($uploadedFiles) { foreach ($uploadedFiles as $fileKey => $fileVal) { $fileName = str_replace(array(" ", "-"), "_", $fileVal->name); list($baseName, $ext) = explode(".", $fileName); $fileName = $baseName . "_" . $fileExtName . "." . $ext; list($thisWidth, $thisHeight, $type, $attr) = getimagesize($fileVal->tempName); $imageTool = Yii::app()->imagemod->load($fileVal->tempName); if ($thisHeight > $thisWidth) { //verticle image if ($thisHeight > $newResizeHeight) { $imageTool->image_resize = true; $imageTool->image_ratio_x = true; $imageTool->image_y = $newResizeHeight; } } else { //horizontal image if ($thisWidth > $newResizeWidth) { $imageTool->image_resize = true; $imageTool->image_ratio_y = true; $imageTool->image_x = $newResizeWidth; } } $imageTool->file_new_name_body = $baseName . "_" . $fileExtName; $imageTool->file_new_name_ext = $ext; $imageTool->process($filePath); if ($imageTool->processed) { $file = new $modelName(); $file->recordId = $id; $file->recordType = $recordType; $file->realName = $fileVal->name; $file->name = $fileName; $file->mimeType = $fileVal->type; $file->fullPath = realpath($filePath); $file->save(false); $uploadedFilesIds[$file->id] = $file->id; } } } return $uploadedFilesIds; } else { return false; } }
public function actionImport() { $model = new Maestrocompo(); $model->setScenario("cargamasiva"); if (isset($_POST['Maestrocompo'])) { echo " Si salio el POST OK -> "; $model->attributes = $_POST['Maestrocompo']; $filelist = CUploadedFile::getInstancesByName('csvfile'); // if($filelist) // $model->csvfile=1; //if($model->validate()) // { // echo " Se valido ...."; foreach ($filelist as $file) { try { $transaction = Yii::app()->db->beginTransaction(); $handle = fopen("{$file->tempName}", "r"); echo "el handle es ...." . gettype($handle); $row = 2; ini_set('max_execution_time', '120'); while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { if ($row > 1) { $newmodel = new Maestrocompo(); $newmodel->codigo = $data[0]; $newmodel->um = $data[1]; $newmodel->codtipo = $data[2]; $newmodel->descripcion = $data[3]; $newmodel->marca = $data[4]; $newmodel->marca = $data[5]; $newmodel->marca = $data[6]; //$newmodel->setScenario("cargamasiva"); /*$newmodel->cantlibre=$data[1]; echo " el id a cargar es : ".$data[0]." \n";*/ if ($newmodel->save()) { //echo " grabo carajo --------------------> : ".$data[1]." \n"; echo "ok " . $newmodel->codigo . "\n"; } else { //echo " NO grabo xxxxxxxxxxx-> : ".$data[1]." \n"; } } $row++; } $transaction->commit(); } catch (Exception $error) { print_r($error); $transaction->rollback(); } yii::app()->end(); } } else { echo "NO se ha enviado ningun form"; } $this->render('cargamaestro', array('model' => $model)); }
/** * What the hell is this method? it was discussed over 9000 times that such code * should not be anywhere close to controller as it is pure model's logic. * * @param $model * @param $instanceName * @param $recordType * @return array */ private function saveImages($model, $instanceName, $recordType) { /** @var $images CUploadedFile[] */ $images = CUploadedFile::getInstancesByName($instanceName); $imagePath = $this->pathToImages . "/" . $model->id; $newResizeWidth = 1920; $newResizeHeight = 1024; Yii::app()->file->set($imagePath)->createDir(0777); $ids = array(); if ($images) { if (File::model()->findByAttributes(['recordId' => $model->id, 'recordType' => $recordType])) { File::model()->findByAttributes(['recordId' => $model->id, 'recordType' => $recordType])->delete(); } foreach ($images as $num => $pic) { $imageNameAr = explode(".", $pic->name); $fileName = $recordType; $ext = end($imageNameAr); $imageName = $fileName . '.' . $ext; list($thisWidth, $thisHeight, $type, $attr) = getimagesize($pic->tempName); $imageTool = Yii::app()->imagemod->load($pic->tempName); if ($thisHeight > $thisWidth) { //verticle image if ($thisHeight > $newResizeHeight) { $imageTool->image_resize = true; $imageTool->image_ratio_x = true; $imageTool->image_y = $newResizeHeight; } } else { //horizontal image if ($thisWidth > $newResizeWidth) { $imageTool->image_resize = true; $imageTool->image_ratio_y = true; $imageTool->image_x = $newResizeWidth; } } $imageTool->file_new_name_body = $fileName; $imageTool->file_new_name_ext = $ext; $imageTool->process($imagePath); if ($imageTool->processed) { $img = new File(); $img->recordId = $model->id; $img->recordType = $recordType; $img->realName = $pic->name; $img->name = $imageName; $img->mimeType = $pic->type; $img->fullPath = realpath($imagePath); $img->save(false); $ids[$img->id] = $img->id; } } } return $ids; }
/** * Returns an array of instances starting with specified array name. * * If multiple files were uploaded and saved as 'Files[0]', 'Files[1]', 'Files[n]'..., you can have them all by * passing 'Files' as array name. * * @param string $name The name of the array of files * @param bool $lookForSingleInstance If set to true, will look for a single instance of the given name. * * @return UploadedFile[] The array of UploadedFile objects. Empty array is returned if no adequate upload was * found. Please note that this array will contain all files from all subarrays regardless * how deeply nested they are. */ public static function getInstancesByName($name, $lookForSingleInstance = true) { $name = static::_normalizeName($name); $instances = parent::getInstancesByName($name); if (!$instances && $lookForSingleInstance) { $singleInstance = parent::getInstanceByName($name); if ($singleInstance) { $instances[] = $singleInstance; } } return $instances; }
public function actionImport() { $model = new Alinventario(); $model->setScenario("cargamasiva"); if (isset($_POST['Alinventario'])) { echo " Si salio el POST OK -> "; $model->attributes = $_POST['Alinventario']; $filelist = CUploadedFile::getInstancesByName('csvfile'); // if($filelist) // $model->csvfile=1; //if($model->validate()) // { // echo " Se valido ...."; foreach ($filelist as $file) { try { $transaction = Yii::app()->db->beginTransaction(); $handle = fopen("{$file->tempName}", "r"); echo "el handle es ...." . gettype($handle); $row = 1; while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { if ($row > 1) { $newmodel = Alinventario::model()->findByPk($data[0]); $newmodel->setScenario("cargamasiva"); $newmodel->cantlibre = $data[1]; echo " el id a cargar es : " . $data[0] . " \n"; if ($newmodel->save()) { echo " grabo carajo --------------------> : " . $data[1] . " \n"; } else { echo " NO grabo xxxxxxxxxxx-> : " . $data[1] . " \n"; } } $row++; } $transaction->commit(); } catch (Exception $error) { print_r($error); $transaction->rollback(); } yii::app()->end(); } //} else // { // echo "NO se valido CSM "; //yii::app()->end(); //} } else { echo "NO se ha enviado ningun form"; //yii::app()->end(); } $this->render('cargainventario', array('model' => $model)); }
public function atualizar($model, $caminho = false) { $nm = ''; $i = 0; $max = 2; $nothing_uploads = false; if (!is_dir($caminho . $model->itens_id)) { mkdir($caminho . $model->itens_id); } for ($i = 0; $i <= $max; $i++) { $img_add = new ItensMultimidia(); $pic = CUploadedFile::getInstancesByName('ItensMultimidia_' . $i); $pic = isset($pic[0]) ? $pic[0] : null; if (isset($pic)) { $nothing_uploads = true; $nm = md5(date("Ymd h:i:s")) . rand(5, 15) . "." . $model->extensionImg($pic->type); if ($pic->saveAs($caminho . $model->itens_id . DIRECTORY_SEPARATOR . $nm, true)) { $img_add = new ItensMultimidia(); $img_add->itens_multimidia_caminho = $nm; $img_add->itens_id = $model->itens_id; /* Checa a existência do id na tabela multimidia */ $iTM = isset($_POST[md5("alt_id_upload-" . $i)]) ? ItensMultimidia::model()->findByPk($_POST[md5("alt_id_upload-" . $i)]) : NULL; if (isset($iTM) && $iTM->count()) { $img_add = ItensMultimidia::model()->findByPk($_POST[md5("alt_id_upload-" . $i)]); $img_add->itens_multimidia_id = $iTM->itens_multimidia_id; $img_add->itens_multimidia_caminho = base64_decode($_POST["files_actual_" . $i]); $img_add->itens_id = $model->itens_id; } try { $img_add->save(); } catch (CDbException $e) { $transaction->rollback(); $model->addError(null, $e->getMessage()); } } } } if ($nothing_uploads == false) { /* Deleta ou atualiza a tabela multimidia */ for ($i = 0; $i <= $max; $i++) { try { $EXC = isset($_POST["itens_multimidia_excluir_" . $i]) ? ItensMultimidia::model()->deleteByPk(base64_decode($_POST["itens_multimidia_excluir_" . $i])) : ''; isset($_POST["itens_multimidia_excluir_" . $i]) && file_exists($caminho . $model->itens_id . DIRECTORY_SEPARATOR . base64_decode($_POST["files_actual_" . $i])) ? unlink($caminho . $model->itens_id . DIRECTORY_SEPARATOR . base64_decode($_POST["files_actual_" . $i])) : ''; } catch (CDbException $e) { //$transaction->rollback(); echo $e->getMessage(); } } } }
/** * 多文件上传。key默认为images * @param CModel $model * @return null */ public function multiImageUpload($model) { $files = array(); if (isset($_FILES['image'])) { $images = CUploadedFile::getInstancesByName('image'); if (isset($images) && count($images) > 0) { foreach ($images as $image => $pic) { $prefix = YII::app()->user->userId . time() . $image . '.'; $imageName = $prefix . $pic->extensionName; $pic->saveAs($this->savePath . $imageName); $files['origin'][$image] = $imageName; $files['thumb'][$image] = $this->saveThumb($prefix, $pic->extensionName); } } } $model->images = CJSON::encode($files); }
public function save($runValidation = true, $attributes = NULL) { $class = get_class($this); if ($class == 'Accounts') { if (Accounts::model()->findByPk($this->id)) { $this->isNewRecord = false; } } $a = parent::save($runValidation, $attributes); if ($a) { //if (isset($_POST['Files'])) { //$this->attributes = $_POST['Files']; $tmps = CUploadedFile::getInstancesByName('Files'); // proceed if the images have been set if (isset($tmps) && count($tmps) > 0) { Yii::log('saved', 'info', 'app'); // go through each uploaded image $configPath = Yii::app()->user->settings["company.path"]; foreach ($tmps as $image => $pic) { $img_add = new Files(); $img_add->name = $pic->name; //it might be $img_add->name for you, filename is just what I chose to call it in my model $img_add->path = "files/"; $img_add->parent_type = get_class($this); $img_add->parent_id = $this->id; // this links your picture model to the main model (like your user, or profile model) $img_add->save(); // DONE if ($pic->saveAs($img_add->getFullFilePath())) { // add it to the main model now } else { echo 'Cannot upload!'; } } if (isset($_FILES)) { Yii::log(print_r($_FILES, true), 'info', 'app'); unset($_FILES); $tmps = CUploadedFile::reset(); } //} } } //endFile return $a; }
/** * Upload a new document. * * @author Kuldeep Dangi <*****@*****.**> */ public function actionUpload() { //name,category_id,images,description,price,userid, $model = new Extensions(); if (!empty($_POST['user_id'])) { $userModel = Users::model()->findByPk($_POST['user_id']); if ($userModel) { $model->attributes = $_POST; $uploadedFiles = CUploadedFile::getInstancesByName('images'); if ($uploadedFiles && count($uploadedFiles) > 0) { $allUploadedFiles = array(); foreach ($uploadedFiles as $uploadedFile) { $fileName = strtotime($this->getCurrentDateTime()) . '-' . $uploadedFile; $uploadedFile->saveAs(Yii::app()->basePath . '/../../' . Extensions::FILE_UPLOAD_PATH . $fileName); $allUploadedFiles[] = $fileName; } $savedFileNames = $model->getPdfFromImages($allUploadedFiles); $model->pdf = Extensions::FILE_CONVERT_PATH . $savedFileNames['pdf']; $model->imagepdf = $savedFileNames['imagepdf']; $model->image = Extensions::FILE_IMAGE_PATH . $savedFileNames['image']; if ($model->save()) { //Update Reward points // $userModel->rewardpoints = $userModel->rewardpoints + // self::REWARD_ON_NOTE_UPLOAD; // $userModel->save(); $nCash = new Ncash(); $nCash->addAmount($userObj->user_id, self::REWARD_ON_NOTE_UPLOAD, 2); $notficationModel = new Notifications(); $notficationModel->sendPushNotification(array('deviceToken' => $userModel->deviceToken, 'deviceType' => $userModel->deviceType, 'message' => 2)); $this->result['success'] = true; } else { $this->result['message'] = 'Record save failed.'; } } else { $this->result['message'] = 'No images to save'; } } else { $this->result['message'] = 'User does not exist.'; } } else { $this->result['message'] = 'Invalid user id.'; } $this->sendResponse($this->result); }
/** * Action which handles file uploads * * The result is an json array of all uploaded files. */ public function actionUpload() { // Object which the uploaded file(s) belongs to (optional) $object = null; $objectModel = Yii::app()->request->getParam('objectModel'); $objectId = Yii::app()->request->getParam('objectId'); if ($objectModel != "" && $objectId != "") { $givenObject = $objectModel::model()->findByPk($objectId); // Check if given object is HActiveRecordContent or HActiveRecordContentAddon and can be written by the current user if ($givenObject !== null && ($givenObject instanceof HActiveRecordContent || $givenObject instanceof HActiveRecordContentAddon) && $givenObject->content->canWrite()) { $object = $givenObject; } } $files = array(); foreach (CUploadedFile::getInstancesByName('files') as $cFile) { $files[] = $this->handleFileUpload($cFile, $object); } return $this->renderJson(array('files' => $files)); }
public function actionCustomer() { $this->layout = false; if (isset($_POST['feedback'])) { $model = new Feedback(); $errorMessage = null; $createFeedback = json_decode($_POST['feedback'], true); if (!isset($createFeedback['order_id']) || !Order::model()->existOrderByOrderId($createFeedback['order_id'])) { $errorMessage = Yii::t('feedback', 'Error orderid, please try again!'); $this->render('customer', array('errorMessage' => $errorMessage)); return 0; } elseif (is_dir("images/feedback/" . $createFeedback['order_id'])) { $errorMessage = Yii::t('feedback', 'Feedback has already submited please wait!'); $this->render('customer', array('errorMessage' => $errorMessage)); return 0; } elseif (!isset($createFeedback['content_text']) || $createFeedback['content_text'] === null) { $errorMessage = Yii::t('feedback', 'Text can not be blank!'); $this->render('customer', array('errorMessage' => $errorMessage)); return 0; } else { $model->order_id = $createFeedback['order_id']; $model->text = $createFeedback['content_text']; $model->contact_method = isset($createFeedback['contact_method']) ? $createFeedback['contact_method'] : null; $model->create_time = date("Y-m-d H:i:s"); $model->dealed = 2; $images = CUploadedFile::getInstancesByName('image'); if (isset($images)) { mkdir(Yii::getPathOfAlias('webroot') . '/images/feedback/' . $model->order_id . '/'); chmod(Yii::getPathOfAlias('webroot') . '/images/feedback/' . $model->order_id . '/', 0755); if (isset($images) && count($images) > 0) { foreach ($images as $image => $pic) { $pic->saveAs(Yii::getPathOfAlias('webroot') . '/images/feedback/' . $model->order_id . '/' . $pic->name); } } $model->photo_name = "feedback.png"; } if (!$model->save()) { $errorMessage = Yii::t('feedback', 'Feedback message has error, please try again!'); } } $this->render('customer', array('errorMessage' => $errorMessage)); } }
public function getuppload_files() { $session = new CHttpSession(); $session->open(); $folder = $_SERVER['DOCUMENT_ROOT'] . '/upload/tmp/' . $session->SessionID; $files = array(); if (is_dir($folder)) { $files = CFileHelper::findFiles($folder, array('level' => 0)); } if (!$this->isimport) { if (!$files) { return CUploadedFile::getInstancesByName(''); } else { return $files; } } else { return array(123, 321); } }
public function actionIndex() { if (!empty($_POST)) { $images = CUploadedFile::getInstancesByName('images'); if (isset($images) && count($images) > 0) { // go through each uploaded image foreach ($images as $image => $pic) { $model = new Images(); $model->scenario = 'image'; $imageName = $this->getFileName($pic); $model->image = $imageName; if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName)) { $model->link = $imageName; $model->name = $pic->name; $model->created = time(); $model->album_id = Images::$IMAGE_PHOTO; //dump($model); if ($model->save()) { Yii::app()->user->setFlash('success', translate('Thêm thành công.')); } else { dump($model->errors); } } // handle the errors here, if you want } } $this->redirect(PIUrl::createUrl('admin/images/index')); } $criteria = new CDbCriteria(); $criteria->condition = 'album_id=:album_id'; $criteria->order = 'id DESC'; $criteria->params = array(':album_id' => Images::$IMAGE_PHOTO); $count = Images::model()->count($criteria); $pages = new CPagination($count); // results per page $pages->pageSize = 18; $pages->applyLimit($criteria); $listImage = Images::model()->findAll($criteria); //dump($model); $dataAlbums = Albums::model()->getAlbums(); $this->render('index', compact('pages', 'dataAlbums', 'listImage')); }
public function actionOuterLinkPhotos($id) { $this->layout = '//layouts/new/main'; $model = $this->loadModel($id); if (isset($_POST['uploadOuterLinkImage']) && $_POST['uploadOuterLinkImage']) { $images = CUploadedFile::getInstancesByName('OuterLinkImage'); if ($images) { foreach ($images as $num => $pic) { $photo = new OuterLinkImage(); $photo->recordId = $id; $photo->file = $pic; if (!$photo->save()) { echo "<pre style='color:blue' title='" . __FILE__ . "'>" . basename(__FILE__) . ":" . __LINE__ . "<br>"; print_r($photo->getErrors()); echo "</pre>"; } } } } $this->render('photos', array('model' => $model)); }
public function actionUpdate($id) { $model = $this->loadModel($id); $photo = Image::model()->findAllByAttributes(array('imageid' => $id)); if (isset($_POST['News'])) { $photos = CUploadedFile::getInstancesByName('images'); $url = array(); foreach ($photos as $files) { $fn = $files->getTempName(); $client_id = "c633cc927c486e6"; $handle = fopen($fn, "r"); $data = fread($handle, filesize($fn)); $pvars = array('image' => base64_encode($data)); $timeout = 30; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json'); curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id)); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $out = curl_exec($curl); curl_close($curl); $pms = json_decode($out, true); array_push($url, $pms['data']['link']); } $model->attributes = $_POST['News']; if ($model->save()) { foreach ($url as $path) { $model_image = new Image(); $model_image->imageid = $model->id; $model_image->path = $path; $model_image->save(); } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'photo' => $photo)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Imagesdetail(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Imagesdetail'])) { $model->attributes = $_POST['Imagesdetail']; $imagelist = CUploadedFile::getInstancesByName('image'); if (isset($imagelist) && count($imagelist) > 0) { $folder = 'upload/' . date('Ymd'); if (!file_exists($folder)) { mkdir($folder); } foreach ($imagelist as $image => $pic) { $time = time(); if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/' . $folder . '/' . $time . $pic->name)) { $imageitem = new Imagesdetail(); $imageitem->image = $folder . '/' . $time . $pic; $imageitem->name = $pic->name; $imageitem->albumid = $model->albumid; $imageitem->status = 1; $imageitem->create = time(); $imageitem->insert(); } } $this->redirect(array('admin')); } else { $model->attributes = $_POST['Imagesdetail']; if ($model->save()) { //$model->image->saveAs($folder.'/'.$model->image); // $model->image = $folder.'/'.$model->image; // $model->update(array('image')); $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($id) { $regions = Region::getRegionList(); $model = new Ad(); $model->attachEavSet(Category::model()->findByPk($id)->set_id); $model->category_id = $id; $photo = new Photo(); if (isset($_POST['Ad'])) { $model->attributes = $_POST['Ad']; $model->author_id = Yii::app()->user->id; $transaction = Yii::app()->db->beginTransaction(); if ($model->saveWithEavAttributes()) { $images = CUploadedFile::getInstancesByName('images'); if ($images) { $wrongImage = Photo::validateMultiple($images, $model->id); if (!$wrongImage) { foreach ($images as $image) { $photo = new Photo(); $photo->image = $image; $photo->name = $photo->image->getName(); $photo->ad_id = $model->id; $photo->save(false); } $transaction->commit(); $this->redirect(array('view', 'id' => $model->id)); } else { $photo = $wrongImage; $transaction->rollback(); } } else { $transaction->commit(); SphinxService::saveAdToRt($model->id); $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('create', array('model' => $model, 'photo' => $photo, 'regions' => $regions)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Personaje(); $user = Yii::app()->user; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Personaje'])) { $model->attributes = $_POST['Personaje']; if ($model->save()) { $images = CUploadedFile::getInstancesByName('picture'); if (isset($images) && count($images) > 0) { foreach ($images as $image => $pic) { $pic->saveAs(Yii::app()->getBasePath() . '/../images/' . $pic->name); $model->imagen = $pic->name; $model->save(); } } $user->setFlash('success', "Datos han sido guardados <strong>satisfactoriamente</strong>."); $this->redirect(array('create')); } } $this->render('create', array('model' => $model)); }
public function actionCustomer() { $this->layout = false; if (isset($_POST['feedback'])) { $model = new Feedback(); $errorMessage = null; $createFeedback = json_decode($_POST['feedback'], true); $sql_existFeedback = "SELECT * FROM `st_feedback` WHERE order_id = '" . $createFeedback['order_id'] . "'"; if (!Order::model()->existOrderByOrderId($createFeedback['order_id'])) { $errorMessage = "订单号有错,请核实后重新输入"; } elseif (is_dir("images/feedback/" . $createFeedback['order_id'])) { $errorMessage = "已经提交过问题,请等候处理,或直接与客服人员联系"; } else { $model->order_id = $createFeedback['order_id']; $model->text = $createFeedback['content_text']; $model->contact_method = isset($createFeedback['contact_method']) ? $createFeedback['contact_method'] : null; $model->create_time = date("Y-m-d H:i:s"); $model->dealed = 2; if (!$model->save()) { $errorMessage = "提交的信息可能有误,请重新提交或者与客服联系。"; } if (isset($_POST['image'])) { $images = CUploadedFile::getInstancesByName('image'); if (isset($images) && count($images) > 0) { foreach ($images as $image => $pic) { $pic->saveAs(Yii::getPathOfAlias('webroot') . '/images/feedback/' . $order_id . $pic->name); } } $model->photo_name = "feedback.png"; } if (!$model->save()) { $errorMessage = "提交的信息可能有误,请重新提交或者与客服联系。"; } } $this->render('customer', array('errorMessage' => $errorMessage)); } }