本文整理汇总了PHP中UploadedFile::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getInstance方法的具体用法?PHP UploadedFile::getInstance怎么用?PHP UploadedFile::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImageOriginal
public function getImageOriginal()
{
if (file_exists($this->pathForIcons . "/apple-icon-original.png")) {
$this->imageOriginal = UploadedFile::getInstance($model, 'imageOriginal');
}
return $this->imageOriginal;
}
示例2: actionUpload
public function actionUpload()
{
$model = new UploadForm();
if (Yii::$app->request->isPost) {
$tanggal = date("YmdHis");
$model->file = UploadedFile::getInstance($model, 'file');
if ($model->file && $model->validate()) {
$model->file->saveAs('uploads/data_prospek/' . $model->file->baseName . $tanggal . '.' . $model->file->extension);
//$this->actionExupload();
}
}
return $this->render('upload', ['model' => $model]);
}
示例3: actionCreate
public function actionCreate()
{
$model = new MeForm();
if ($model->load(Yii::$app->request->post())) {
$model->file = UploadedFile::getInstance($model, 'file');
$photoName = 'uploads/' . $model->title . '.' . $model->file->extension;
$model->file->saveAs($photoName);
$model->photo = $photoName;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: run
/**
* @inheritdoc
*/
public function run()
{
$model = $this->model;
if ($model->load($_POST)) {
$file = UploadedFile::getInstance($model, 'file');
$model->fileName = $file->getBaseName() . '.' . $file->getExtension();
if ($model->validate()) {
$uploaded = $file->saveAs(Yii::getAlias('@app/web/imgs') . "/{$model->path}");
} else {
print_r($model->getErrors());
}
}
Yii::$app->response->format = Response::FORMAT_JSON;
return ['files' => [['url' => "/imgs/{$model->path}", 'name' => 'name', 'type' => 'type', 'size' => 18932, 'deleteUrl' => 'url', 'deleteType' => 'DELETE']]];
}
示例5: saveUploadedFile
public function saveUploadedFile($model, $attribute, $fileName = null, $obj = false, $returnObj = false)
{
$result = UploadedFile::getInstance($model, $attribute);
if ($fileName == null) {
$fileName = time() . '.' . $result->getExtension();
}
if (strpos($fileName, "/") !== false) {
$fileSubPath = substr($fileName, 0, strrpos($fileName, "/"));
if (!is_dir($this->basePath . '/' . $fileSubPath)) {
mkdir($this->basePath . '/' . $fileSubPath, $this->filePermission, true);
}
}
if ($result->saveAs($this->basePath . "/" . $fileName)) {
chmod($this->basePath . "/" . $fileName, $this->filePermission);
}
return $returnObj ? $returnObj : $fileName;
}
示例6: actionUpdate
/**
* Updates an existing News model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$form = new UploadForm();
if ($model->load(Yii::$app->request->post())) {
if ($form->image = UploadedFile::getInstance($form, 'image')) {
$model->pic = 'image/' . md5($_SERVER['REQUEST_TIME'] . $form->image->baseName) . $_SERVER['REQUEST_TIME'] . '.' . $form->image->extension;
$form->image->saveAs($model->pic);
}
if ($model->type != 4) {
$model->pic = '';
}
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', ['model' => $model, 'uploadForm' => $form]);
}
}