【问题标题】:Symfony, how to read and upload epub file in google storage and read itSymfony,如何在谷歌存储中读取和上传 epub 文件并阅读它
【发布时间】: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 中上传txtdoc 文件时,我有UploadFile 类与*SplFileInfo*pathName = "/tmp/phpJKcZTL" *SplFileInfo*fileName = "phpJKcZTL" 的文件
  • 您忘记分享您的错误信息。如果您上传文本或文字文件,一切正常吗?
  • @NicoHaase 是的,上传文本或世界或图像时一切正常。错误消息 - Warning: file_get_contents(): Filename cannot be empty

标签: php symfony google-cloud-storage epub


【解决方案1】:

我发现,php.ini upload_max_filesize 增加后 - 文件上传路径和名称并获取内容并写入谷歌存储。因为需要关注 UploadedFile 类中的错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    相关资源
    最近更新 更多