【问题标题】:Save a file as a BLOB with Doctrine使用 Doctrine 将文件另存为 BLOB
【发布时间】:2012-05-10 06:11:55
【问题描述】:

我将 Symfony2 与 Doctrine 2.2.2 和一个 Oracle 数据库一起使用。我想在 Oracle DB 中将文件另存为 BLOB。我为 Doctrine 写了一个服装类型来拥有一个 BLOB 类型。它看起来像这样:

class Blob extends Type
{
const BLOB = 'blob';


public function convertToPHPValue($value, AbstractPlatform $platform)
{
    return (is_resource($value)) ? stream_get_contents($value) : $value;
}

public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
    return 'BLOB';
}

public function getBindingType() {
    return \PDO::PARAM_LOB;
}

public function getName()
{
    return self::BLOB;
}
}

保存文件的实体如下:

<?php

class Document
{
/**
 * @var integer $id
 */
private $id;

/**
 * @var file $file
 */
private $file;

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set file
 *
 * @param blob $file
 */
public function setFile($file)
{
    $this->file = $file;
}

/**
 * Get file
 *
 * @return blob 
 */
public function getFile()
{
    return $this->file;
}
}

当我想用我的控制器原则保存文件时,只保存上传文件时将创建的临时文件的路径。

【问题讨论】:

  • 你找到解决办法了吗?

标签: php oracle symfony doctrine-orm


【解决方案1】:

$file 变量似乎不是资源。

你可以试试这个:

public function convertToPHPValue($value, AbstractPlatform $platform)
{
    return is_file($value) ? file_get_contents($value) : $value;
}

【讨论】:

  • 不,这也不起作用。 Doctrine 只保存临时上传文件的路径,并在我想从数据库下载它时返回这个路径。
  • 您确定您的 blob 类型已正确注册和使用吗?
【解决方案2】:

这里的 Doctrine\DBAL\Types\BlobType 似乎是学说 2.2 中的 blob 类型

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-04
    • 2018-06-11
    • 2011-07-12
    • 2011-01-17
    • 2016-07-02
    • 2019-02-16
    • 2012-10-25
    • 2017-10-02
    相关资源
    最近更新 更多