Hi
I’m trying upload specific files.
This is my code:
[['file'], 'file', 'extensions' => ['pdf','php'], 'wrongExtension'=>'pdf,php files only'],
When i try upload pdf, works great, but when i try upload php file say: "pdf,php files only". (after click in submit button)
I tried too, txt, js, etc…and i have the same problem.
print_r($att->file);
yii\web\UploadedFile Object ( [name] => backup-restore-mysql.pdf [tempName] => C:\xampp\tmp\php8364.tmp [type] => application/pdf [size] => 310139 [error] => 0 )
yii\web\UploadedFile Object ( [name] => requirements.php [tempName] => C:\xampp\tmp\phpE22C.tmp [type] => application/octet-stream [size] => 5051 [error] => 0 )
Controller:
if ($att->load(Yii::$app->request->post()) && $att->validate()){
$att->file = UploadedFile::getInstance($att, 'file');
if (!empty($att->file)){
$extension = $att->file->extension;
$att->Filename = $att->file->baseName;
$att->Extension = $extension;
$att->Size = $att->file->size;
$att->C_Id = $id;
//$att->save();
if ($att->save()){
if(!is_dir('files/'.$extension.'/')){
mkdir(('files/'.$extension.'/'));
}
$att->file->saveAs('files/'.$extension.'/'.$att->file->name);
}
}
}
What i’m doing wrong?