本文整理汇总了PHP中CUploadedFile::getInstancesByName方法的典型用法代码示例。如果您正苦于以下问题:PHP CUploadedFile::getInstancesByName方法的具体用法?PHP CUploadedFile::getInstancesByName怎么用?PHP CUploadedFile::getInstancesByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUploadedFile
的用法示例。
在下文中一共展示了CUploadedFile::getInstancesByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* 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));
}
示例2: actionCreate
/**
* 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));
}
示例3: saves
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;
}
示例4: actionEdit
/**
* 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));
}
示例5: actionContact
/**
* 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('admin@cads.mys', $model->name);
$mail->Subject = $model->subject;
$msg = $model->body . '<br />' . $model->email . '<br/>' . $model->name;
$mail->MsgHTML($msg);
$mail->CharSet = "UTF-8";
$mail->AddAddress('zmahazhir@gmail.com', "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));
}
示例6: actionUpdate
/**
* 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));
}
示例7: actionIndex
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'));
}
示例8: actionUpload
/**
* 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));
}
示例9: getuppload_files
public function getuppload_files()
{
if (!$this->isimport) {
return CUploadedFile::getInstancesByName('');
} else {
return array(123, 321);
}
}
示例10: updateProductImages
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();
}
}
示例11: testGetInstancesByNamePartOfOtherName
/**
* @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!');
}
}
示例12: actionUpload
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;
}
}
示例13: actionImport
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));
}
示例14: saveImages
/**
* 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;
}
示例15: getInstancesByName
/**
* 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;
}