s3 上的文件上传:无法打开流:没有这样的文件或目录
File upload on s3 : failed to open stream: No such file or directory
我在 S3 上上传文件时遇到问题 aws.The 文件扩展名为 .pdf。我收到来自 FormData class AJAX.I 处理文件并上传 s3 的请求。但是出了点问题……你能问我吗?
框架 => Yii2...
控制器:
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();
}
}
文件格式
$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,'');
和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);
谢谢...
您可能需要目录分隔符
$file = fopen($path . DIRECTORY_SEPARATOR . $fileName,'w');
.
'file_name' =>$path . DIRECTORY_SEPARATOR . $fileName,
我在 S3 上上传文件时遇到问题 aws.The 文件扩展名为 .pdf。我收到来自 FormData class AJAX.I 处理文件并上传 s3 的请求。但是出了点问题……你能问我吗? 框架 => Yii2...
控制器:
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();
}
}
文件格式
$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,'');
和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);
谢谢...
您可能需要目录分隔符
$file = fopen($path . DIRECTORY_SEPARATOR . $fileName,'w');
.
'file_name' =>$path . DIRECTORY_SEPARATOR . $fileName,