Answer the question
In order to leave comments, you need to log in
Are files not being uploaded to the server at the same time?
I've been sitting all night, ready not to cook, help! Help me)
Here is such a controller:
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->image = UploadedFile::getInstance($model,'image');
if( $model->image ) {
$model->upload();
}
$mfile = UploadedFile::getInstance($model, 'file');
$model->bookfile = $mfile->name;
$ext = end((explode(".", $mfile->name)));
$model->bookfile = Yii::$app->security->generateRandomString().".{$ext}";
$path2 = Yii::getAlias('@webroot').'/upload/global/books/'.$model->bookfile;
if($model->save()) {
$mfile->saveAs($path2);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return false;
}
return $this->redirect(['view', 'id' => $model->id]);
}
else {
return $this->render('update', compact('model'));
}
}
public function rules() {
return [
[['image'],'file','extensions' => 'png, jpg'],
[['file'],'file','extensions' => 'txt,doc,pdf'],
];
}
public function upload() {
if($this->validate()) {
$path = 'upload/store/'.$this->image->baseName.'.'.$this->image->extension;
$this->image->saveAs($path);
$this->attachImage($path, true);
@unlink($path);
return true;
}
else { return false; }
}
finfo_file(D:\OpenServer\userdata\temp\phpCD25.tmp): failed to open stream: No such file or directory
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question