1

我目前正在开发一个脚本,该脚本需要使用 GridFS 将图像存储到 Mongo 中,尽管在检索文件时(使用 php 标头),width="" 和 height="" HTML 已经放置到显示器中,有什么办法吗我更改它还是将它存储在 Mongo/GridFS 中?

// get GridFS files collection
  $grid = $db->getGridFS();

  // retrieve file from collection
  $file = $grid->findOne(array('_id' => new MongoId('4fb437dbee3c471b1f000001')));

  // send headers and file data
  header('Content-Type: image');
  echo $file->getBytes();
  exit;  
4

1 回答 1

1

PHP 不会自己添加那些宽度和高度标签。这可能是您的浏览器为您添加的内容,因此请检查实际通过网络发送的内容!

无论如何,当您在 GridFS 中存储文件时,您可以设置额外的元数据:

$grid->storeFile($filename, array("height" => 42, "width" => 38));

为了利用这些信息,您必须执行一个单独的查询来查询此信息,然后将其注入您的 HTML 代码中。获取元数据的查询可以是:

$file = $grid->findOne(array('_id' => new MongoId('4fb437dbee3c471b1f000001')));
var_dump( $file );
于 2012-05-17T07:49:31.240 回答