I have a problem of my file uploading feature attached into my webapp. code is working perfectly in my localhost but not in the real server which i was uploaded already. and i was changed the directory permission to writable.
if ($model->load(Yii::$app->request->post()))
{
$session = Yii::$app->session;
$user_id = $session->get('role');
//get the instance of the uploaded file
$imageName = $model->Fname."_".$model->Lname;
$model->file = UploadedFile::getInstance($model, 'file');
if($model->file)
{
//SHA512 base password encription
$model->password = crypt($model->repeatpassword,'$6$rounds=1212$16charactersalt');
//save image pathe to db
$model->image = 'uploads/profile_image/'.$imageName.'.'.$model->file->extension;
$model->role = $user_id;
$model->save();
$model->file->saveAs( 'uploads/profile_image/'.$imageName.'.'.$model->file->extension );
}
//return $this->redirect(['index']);
return $this->goHome();
}
I think there is not any issue in your Yii2 code. It may be an issue of PHP configuration.
File Info extension is enabled by default as of PHP 5.3.0
Windows users must include the bundled php_fileinfo.dll DLL file in php.ini to enable this extension.
Please visit below link for more details.
http://php.net/manual/en/fileinfo.installation.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With