Reputation: 81
I have a problem to file upload on S3 aws.The file extension is .pdf. I receive request from FormData class AJAX.I handle file and upload s3. but something is wrong... can you ask me pls ? Framework => Yii2...
Controller :
public function actionUploadFile(){
$path = \Yii::getAlias('@frontend/upload');
$fileName = 'uploaded_file.pdf';
$data = file_get_contents($_FILES['file']['tmp_name']);
$file = fopen($path.$fileName,'w');
fwrite($file,$data);
fclose($file);
$model = new DocumentForm([
'requestType' => DocumentRequestEnum::UPLOAD,
'document_title' => 'test',
'document_description' => 'test123',
'service_provider_id' => 1,
'file_name' =>$path.$fileName,
]);
return $model->upload();
}
}
DocumentForm
$serviceProvider = ServiceProvider::findOne([
'id' => $this->service->id,
]);
$serviceProvider->file_name = $this->file_name;
$serviceProvider->document_title = $this->document_title;
$serviceProvider->document_description = $this->document_description;
$serviceProvider->save(false);
return \Yii::$app->awsDocument->uploadFile($this->file_name,'');
And bucketClass
public function uploadFile($name, $pathOnS3, $options = [])
{
$params = [
'Bucket' => $this->bucket,
'ACL' => $this->acl,
'Key' => ($pathOnS3) ? $pathOnS3 : $this->basePath . basename($name),
'SourceFile' => $name,
];
$params = array_merge($params, $options);
return $this->s3->putObject($params);
thks...
Upvotes: 2
Views: 1290
Reputation: 133370
could be you need directory separator
$file = fopen($path . DIRECTORY_SEPARATOR . $fileName,'w');
.
'file_name' =>$path . DIRECTORY_SEPARATOR . $fileName,
Upvotes: 1