【发布时间】:2018-04-04 12:38:23
【问题描述】:
我与"symfony/symfony": "~3.4", 和"knplabs/gaufrette": "^0.3.0", 合作将媒体上传到谷歌存储。但是如何处理epub 文件,当我在正文post 请求中添加epub 文件时,我的文件没有名称或路径
epubUrl = {Symfony\Component\HttpFoundation\File\UploadedFile} [7]
test = false
originalName = "RU EJTOP epub r1 (2).epub"
mimeType = "application/octet-stream"
size = 0
error = 1
*SplFileInfo*pathName = ""
*SplFileInfo*fileName = ""
和动作捕捉错误
Warning: file_get_contents(): Filename cannot be empty
来自上传功能,因为file_get_contents 需要一些路径
public function upload(
UploadedFile $file,
$target,
$allowedMimeTypesArray,
$name
) {
if (!$allowedMimeTypesArray) {
$allowedMimeTypesArray = self::$allowedMimeTypes;
}
// Check if the file's mime type is in the list of allowed mime types.
if (!in_array($file->getClientMimeType(), $allowedMimeTypesArray, true)) {
throw new \InvalidArgumentException(
sprintf(
'Files of type %s are not allowed.',
$file->getClientMimeType()
)
);
}
$y = file_get_contents($file->getPathname());
$this->storeFile($target, file_get_contents($file->getPathname()), $name);
return $name;
}
private function storeFile($target, $data, $name)
{
/** @var GoogleCloudStorage $fileSystem */
$fileSystem = $this->getFileSystem($target);
if (false === $fileSystem->write($name, $data)) {
throw new \Exception('Storing file failed');
}
}
如何将 epub 文件上传到谷歌存储然后阅读? 以及它如何与 php 中的 epub 文件一起使用?
【问题讨论】:
-
您确定您的上传工作正常吗?它适用于 Word 文件还是纯文本文件?
-
@NicoHaase 我检查了,当在
request中上传txt或doc文件时,我有UploadFile类与*SplFileInfo*pathName = "/tmp/phpJKcZTL" *SplFileInfo*fileName = "phpJKcZTL"的文件 -
您忘记分享您的错误信息。如果您上传文本或文字文件,一切正常吗?
-
@NicoHaase 是的,上传文本或世界或图像时一切正常。错误消息 -
Warning: file_get_contents(): Filename cannot be empty
标签: php symfony google-cloud-storage epub