本文整理汇总了PHP中CUploadedFile::getInstances方法的典型用法代码示例。如果您正苦于以下问题:PHP CUploadedFile::getInstances方法的具体用法?PHP CUploadedFile::getInstances怎么用?PHP CUploadedFile::getInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUploadedFile
的用法示例。
在下文中一共展示了CUploadedFile::getInstances方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UploadPhotos
public function UploadPhotos($model, $path)
{
$root = $_SERVER['DOCUMENT_ROOT'] . '/' . $path;
$files = CUploadedFile::getInstances($model, 'p_path');
// print_r($files);exit;
$return = '';
$n = 1;
foreach ($files as $file) {
$pre = rand(999, 9999) . time() . $n;
if ($file && ($file->type == "image/jpeg" || $file->type == "image/pjpeg" || $file->type == "image/png" || $file->type == "image/x-png" || $file->type == "image/gif")) {
$newName = $pre . '.' . $file->getExtension();
} else {
die('wrong type');
}
if (!is_dir($root)) {
if (!mkdir($root, 0755, true)) {
die('´´ÔìÎļþ¼Ðʧ°Ü...');
}
}
//echo $root.$folder.$newName;exit;
if ($file->saveAs($root . $newName)) {
$return .= $path . $newName . '#';
}
$n++;
}
return $return;
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Pic();
if (isset($_POST['Pic'])) {
$image = CUploadedFile::getInstances($model, 'big_pic');
$is_fail = true;
foreach ($image as $img) {
$model->created_time = date("Y-m-d H:i:s");
$microtime = microtime(true);
$model->big_pic = './images/pic/' . $microtime . '.' . $img->extensionName;
$mini_path = $this->create_mini_pic($img->tempName, $microtime);
$model->mini_pic = $mini_path;
if ($model->save()) {
$is_fail = false;
$img->saveAs($model->big_pic);
} else {
print_r($model->getErrors());
}
}
if (!$is_fail) {
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model));
}
示例3: afterSave
protected function afterSave()
{
parent::afterSave();
$images = CUploadedFile::getInstances($this, 'images');
if (isset($images) && count($images) > 0) {
foreach ($images as $k => $img) {
$imageName = md5(microtime()) . '.jpg';
if ($img->saveAs($this->getFolder() . $imageName)) {
$advImg = new Image();
$advImg->goods_id = $this->getPrimaryKey();
$advImg->image = $imageName;
$advImg->save();
}
}
}
if ($this->isNewRecord) {
$count = new Count();
$count->goods_id = $this->id;
$count->count = $this->count;
$count->size = $this->size;
$count->color = $this->color;
$count->save();
} else {
Count::model()->updateAll(array('goods_id' => $this->id, 'count' => $this->count, 'size' => $this->size, 'color' => $this->color), 'goods_id=:goods_id', array(':goods_id' => $this->id));
}
}
示例4: files
public function files($attribute, $params)
{
$validator = CValidator::createValidator('file', $this, $attribute, $params);
foreach (CUploadedFile::getInstances($this, $attribute) as $file) {
$this->{$attribute} = $file;
$validator->validate($this, $attribute);
}
}
示例5: uploadMultifile
public function uploadMultifile($model, $attr, $path)
{
/*
* path when uploads folder is on site root.*/
$path = '../../uploads/';
if ($sfile = CUploadedFile::getInstances($model, $attr)) {
foreach ($sfile as $i => $file) {
$formatName = time() . $i . '.' . $file->getExtensionName();
$fileName = "{$sfile[$i]}";
$formatName = time() . $i . '_' . $fileName;
//$formatName=$fileName;
$file->saveAs(Yii::getPathOfAlias('webroot') . '/uploads/' . $formatName);
$ffile[$i] = $formatName;
}
return $ffile;
}
}
示例6: _saveFiles
private function _saveFiles(Issue $model)
{
$files = CUploadedFile::getInstances($model, 'tmpFiles');
if (isset($files) && count($files) > 0) {
foreach ($files as $k => $file) {
$ext = pathinfo($file->name, PATHINFO_EXTENSION);
$filename = md5(rand(1000, 4000)) . '.' . $ext;
if ($file->saveAs($model->getFileFolder() . $filename)) {
Yii::app()->image->load($model->getFileFolder() . $filename)->resize(300, 300, Image::WIDTH)->quality(80)->crop(300, 300)->save($model->getFileFolder() . '/thumb_' . $filename);
$image = new IssueFile();
$image->issue_id = $model->getPrimaryKey();
$image->filename = $filename;
$image->save();
}
}
}
}
示例7: actionUpdate
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$model->scenario = 'update';
$model->preUpdate();
$this->performAjaxValidation($model);
if (isset($_POST['ProductCategory'])) {
$model->attributes = $_POST['ProductCategory'];
$model->_images = CUploadedFile::getInstances($model, '_images');
if ($model->validate()) {
if ($model->preSave()) {
Yii::app()->user->setFlash('success_update', true);
$this->redirect(array('index'));
}
//$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('update', array('model' => $model));
}
示例8: beforeSave
protected function beforeSave()
{
if (parent::beforeSave()) {
// Читаем конфигурацию каталога
$galleryConfig = GalleryConfig::model()->findByPk(1);
// Загружаем фотографии
$photos = new GalleryPhoto();
if ($photosUpload = CUploadedFile::getInstances($photos, 'image')) {
foreach ($photosUpload as $file) {
$photo = new GalleryPhoto();
$photoName = md5(time() . $file->name) . '.' . $file->getExtensionName();
$photo->file = $photoName;
$file->saveAs($this->folder . '/' . $photoName);
$this->uploaded_photos[] = $photo;
Yii::app()->ih->load($this->folder . '/' . $photoName)->adaptiveThumb($galleryConfig->prev_x, $galleryConfig->prev_y)->save($this->folder . '/small/' . $photoName, false, 100)->reload()->adaptiveThumb(200, 135)->save($this->folder . '/medium/' . $photoName, false, 100);
}
}
if ($this->isNewRecord) {
$this->sort_order = $this->getMaxSortOrder() + 10;
}
if (!empty($this->uploaded_photos)) {
foreach ($this->uploaded_photos as $photo) {
$photo->gallery_id = $this->id;
$photo->save();
}
if ($this->photos and $coverPhoto = $this->getCover()) {
$this->cover_photo_id = $coverPhoto->id;
}
}
return true;
} else {
return false;
}
}
示例9: actionAjax_upload_doc
public function actionAjax_upload_doc($id)
{
$model = $this->loadModel($id);
if ($model) {
if (isset($_FILES['Listing']) && isset($_POST['Listing']['title_cea'])) {
$totalImgupload = ProListingUploadCea::model()->countByAttributes(array('listing_id' => $id));
if (!ProListingUploadCea::checkLimitFileUpload($id)) {
die("limit");
}
$data = CUploadedFile::getInstances($model, 'file_upload');
if ($_POST['Listing']['title_cea'] != '' && !empty($data)) {
foreach ($data as $k => $file) {
$name = date('d-m-Y-h-i-s') . "." . $file->getExtensionName();
$cea = new ProListingUploadCea();
$cea->attributes = $_POST['Listing'];
$cea->listing_id = $id;
$cea->file_upload = $file;
$cea->file = $name;
$cea->title = isset($_POST['Listing']['title_cea']) ? $_POST['Listing']['title_cea'] : '';
$cea->created_date = date('Y-m-d h:i:s');
$cea->validate();
if ($cea->hasErrors()) {
die('maxsize');
} else {
if ($cea->save()) {
$ImageProcessing = new ImageProcessing();
$ImageProcessing->createSingleDirectoryByPath("/upload/listing/{$id}");
$ImageProcessing->createSingleDirectoryByPath("/upload/listing/{$id}/cea");
$file->saveAs(YII_UPLOAD_DIR . "/listing/{$id}/cea/{$name}");
}
}
}
}
}
}
}
示例10: beforeSave
protected function beforeSave()
{
if (parent::beforeSave()) {
if (($this->scenario == 'insert' || $this->scenario == 'update') && ($file = CUploadedFile::getInstance($this, 'photo'))) {
$extension = strtolower($file->extensionName);
$filename = DFileHelper::getRandomFileName(self::IMAGE_PATH, $extension);
$basename = $filename . '.' . $extension;
$this->deleteDocument();
if ($file->saveAs(self::IMAGE_PATH . '/' . $basename)) {
$this->photo = $basename;
}
} else {
if ($this->scenario == 'update') {
unset($this->photo);
}
}
if ($files = CUploadedFile::getInstances($this, 'photo_other')) {
$array = array();
foreach ($files as $img) {
$extension = strtolower($img->extensionName);
$filename = DFileHelper::getRandomFileName(self::IMAGE_PATH, $extension);
$basename = $filename . '.' . $extension;
array_push($array, $basename);
$img->saveAs(self::IMAGE_PATH . '/' . $basename);
}
if ($photo_other = json_encode($array)) {
$this->photo_other = $photo_other;
}
} else {
if (strtolower($this->scenario) == 'update') {
unset($this->photo_other);
}
}
return true;
} else {
return false;
}
}
示例11: uploadMultifile
static function uploadMultifile($model, $attr)
{
/*
* path when uploads folder is on site root.
* $path='/tmp/attachments/'
*/
if ($files = CUploadedFile::getInstances($model, $attr)) {
$dir = Yii::getPathOfAlias('webroot') . DS . 'upload' . DS . 'emails' . DS . $model->id . DS;
$cFile = Yii::app()->cFile;
//Общая папка
$cFile->createDir($dir);
foreach ($files as $i => $file) {
$file->saveAs($dir . $file->getName());
$ffile[$i] = $file->getName();
}
return $ffile;
}
}
示例12: LoadUploadedeImage
/**
* This should be called first before any of the below method is called, otherwise that will not work
*/
public function LoadUploadedeImage()
{
$this->photos = CUploadedFile::getInstances($this, FileUploadFormModel::MULTI_FILE_FIELD_NAME);
$this->photo = CUploadedFile::getInstance($this, FileUploadFormModel::SINGLE_FILE_FIELD_NAME);
}
示例13: getUpploadedPictures
public function getUpploadedPictures()
{
$session = new CHttpSession();
$session->open();
$folder = $_SERVER['DOCUMENT_ROOT'] . '/upload/tmp/' . $session->SessionID;
if (is_dir($folder)) {
$files = CFileHelper::findFiles($folder, array('level' => 0));
} else {
$files = array();
}
if (!$files) {
$files = CUploadedFile::getInstances($this, 'upploadedPictures');
if (!$files) {
$files = CUploadedFile::getInstancesByName('');
}
return $files;
} else {
return $files;
}
}
示例14: actionUpdateproduct
/** Товары: Редактирование товара */
public function actionUpdateproduct($id)
{
$this->breadcrumbs = array('Список товаров' => array('/catalog/catalog/listelement'), 'Редактирование');
$model = $this->loadModelProduct($id);
$root = CatalogRubrics::getRoot();
$catalog = CMap::mergeArray(array($root->id => $root->name), $root->getFormattedDescendants($root->id));
if (isset($_POST['CatalogElements'])) {
$model->attributes = $_POST['CatalogElements'];
$model->imagefile = CUploadedFile::getInstance($model, 'imagefile');
if (isset($model->imagefile)) {
$ext = pathinfo($model->imagefile);
$model->image = $ext['extension'];
}
if ($model->save()) {
$filepatch = '/../uploads/filestorage/catalog/elements/';
if (isset($model->imagefile) && ($modelSettings = SiteModuleSettings::model()->find('site_module_id = 4'))) {
$filename = $model->id . '.' . $model->image;
$model->imagefile->saveAs(YiiBase::getPathOfAlias('webroot') . $filepatch . $filename);
//Обработка изображения
SiteModuleSettings::model()->chgImgModel($modelSettings, 'GD', 2, $model->id);
}
//загрузка дополнительных картинок
$files = CUploadedFile::getInstances($model, 'imagefiles');
if (!empty($files)) {
foreach ($files as $file) {
$modelImages = new CatalogElementsImages();
$modelImages->elements_id = $model->id;
$modelImages->image_name = $model->id . '_' . md5(date('Y-m-d H:i:s') . '-' . rand());
$ext = pathinfo($file->getName());
$modelImages->image = $ext['extension'];
$modelImages->save();
$uplod_file_url = YiiBase::getPathOfAlias('webroot') . $filepatch . '/' . $modelImages->image_name . '.' . $modelImages->image;
$uplod_file_url = $file->saveAs($uplod_file_url);
}
SiteModuleSettings::model()->chgImgagesCatalogModel($model->id, 'GD');
}
$this->redirect(array('updateproduct', 'id' => $model->id));
}
}
$this->render('formproduct', array('model' => $model, 'root' => $root, 'catalog' => $catalog));
}
示例15: beforeSave
protected function beforeSave()
{
if (!parent::beforeSave()) {
return false;
}
$this->title = ucfirst($this->title);
$this->annotation = ucfirst($this->annotation);
// Сохранение катинок
$images = new NewsImages();
if ($imagesUpload = CUploadedFile::getInstances($images, 'filename')) {
//проверка существования пити, если нет создать
if (!file_exists(self::FOLDER_UPLOAD)) {
mkdir(self::FOLDER_UPLOAD, 0777, true);
}
foreach ($imagesUpload as $file) {
$image = new NewsImages();
$imageName = md5(time() . $file->name) . '.' . $file->getExtensionName();
$image->filename = $imageName;
$file->saveAs(self::FOLDER_UPLOAD . '/' . $imageName);
$this->uploaded_images[] = $image;
}
}
return parent::beforeSave();
}