0

I want to upload a file with a maximum size of 25MB, but it fails and the file does not enter the storage folder. Can enybody say what's wrong?

in php.ini-development and php.ini-production post_max_size = 25M upload_max_filesize = 25M

model

[['publikasi_cetak'],'file','skipOnEmpty'=>TRUE,'extensions'=>'rar','maxSize' => 1024*1024*25],

controller

 public function actionCreate()
{
    $model = new Publikasicetak();
      // [['publikasi_cetak'], 'string', 'max' => 255],
        if ($model->load(Yii::$app->request->post())) 
        {
            $model->tanggal_upload= date('Y-m-d H:i:s');
            $model->username=(Yii::$app->user->identity->username);

            $imageName = $model->judul_cetak;
            $publikasi_cetak = UploadedFile::getInstance($model, 'publikasi_cetak');

            $publikasi_cetak->saveAs('pub_cetak/'.$imageName.'.'.$publikasi_cetak->extension);

            $model->publikasi_cetak = $imageName.'.'.$publikasi_cetak->extension;

            if($model->save())
            {

               $lastInsertID = $model->getPrimaryKey();
               return $this->redirect(['view', 'id' => $lastInsertID]);
            }
           else
           {
               // print_r($model->getErrors()); => check whether any validation errors are there
           }


        } else 
        {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
}
han06
  • 67
  • 1
  • 8

2 Answers2

0

There might be a problem with / in your file path, because Windows and Linux operating systems use different directory separators. So instead of this:

$publikasi_cetak->saveAs('pub_cetak/'.$imageName.'.'.$publikasi_cetak->extension);

Try this:

$publikasi_cetak->saveAs('pub_cetak'.DIRECTORY_SEPARATOR.$imageName.'.'.$publikasi_cetak->extension);
jtate
  • 2,612
  • 7
  • 25
  • 35
RolandsR
  • 1
  • 1
  • I have tried but files over 2MB are not stored in the storage folder. if I upload below 2MB it can be saved – han06 May 08 '19 at 20:35
  • Stupid question, have you restarted your server after changing php.ini? If yes, then check answers about .htaccess file or ini_set_function here: https://stackoverflow.com/questions/2184513/change-the-maximum-upload-file-size/2184541#2184541 – RolandsR May 08 '19 at 20:43
0

if you run your Yii project with

./yii serve

then php.ini that is used will be found in
/etc/php/8.1/cli/php.ini

where 8.1 will be your PHP version update

post_max_size = 25M
upload_max_filesize = 25M

and re-run your project

you may also add <?=phpinfo();?> to see exactly which php.ini file is used by your project

Johnbosco Adam
  • 81
  • 1
  • 11