【发布时间】:2013-01-20 13:33:33
【问题描述】:
我正在尝试使用 Cake PHP 中的 GD lib 创建缩略图。
我可以将调整大小的缩略图写入 tmp 目录,并创建合理的 URL 以显示 tmp 目录中的图像:
//set up empty GD resource
$tmp = imagecreatetruecolor(200*$iw/$ih, 200);
//create thumbnail image in the empty GD resource
imagecopyresampled($tmp, $src, 0, 0, 0, 0,200*$iw/$ih, 200, $iw, $ih);
//build full path to thumbnail in the cakephp tmp directory
$thumbfile = APP.'tmp/thumb.jpg';
//build URL path to the same thumbnail
$thumblink = $this->webroot.'tmp/thumb.jpg';
//write jpeg to the tmp directory
$return=imagejpeg($tmp,$thumbfile);
//write out the image to client browser
echo "<img=\"$thumblink\" alt=\"thumb\" height=\"200\" width=\"200*$iw/$ih\">";
缩略图被创建并写入 tmp 目录,但是当我尝试访问 URL 时,我收到以下错误消息:
Error: TmpController could not be found.
Error: Create the class TmpController below in file: app/Controller/TmpController.php
显然我有一个路由错误 - Cake 尝试调用 tmp 控制器,而不是查看 tmp 目录。我该如何解决这个问题,或者是否有另一种方法可以使用 GD lib 提供临时缩略图? 我计划为每个会话或用户创建唯一的缩略图,但我需要先完成这项工作。
Config/routes.php 中的路由:
Router::connect('/', array('controller' => 'MsCake', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages'));
CakePlugin::routes();
我查看了 ThumbnailHelper,但它没有使用 GD Lib。我还需要能够从外部访问存储在非 apache 可访问目录中的文件,但我什至无法访问任何临时符号链接来访问它们。例如。
- 在 tmp 目录中创建一个临时符号链接,指向相关文件。
- 创建一个 HTML 链接,使用 $this->webroot.'tmp/link-to-myfile' 指向符号链接,如上所述
...我得到与上面相同的错误 - 错误:找不到 TmpController。
【问题讨论】:
标签: cakephp-2.1 tmp