我需要在所有浏览器中生成带有'jpeg'扩展名的图像(具有远程路径)作为用户个人资料图片,因此,我在'routers.php'文件中有如下代码行:
Router::extensions(['jpeg','gif']);
视图中的相应部分如下所示:
echo $this->Html->image(['controller'=>'Images','action'=>'profilePicture'], ['alt' => $user['username'], 'data-lock-picture' => ['controller'=>'Images','action'=>'profilePicture'], '_ext' => 'jpeg']);
ImagesController.php
public function profilePicture() {
$this->render('profilePicture', false);
$this->Images->generateImage();
}
ImagesTable.php
public function generateImage() {
$src_path = 'https://.../photo/username.jpg';
$image_string = file_get_contents($src_path);
if ($image_string !== FALSE) {
$image_identifier = imagecreatefromstring($image_string);
imagejpeg($image_identifier);
}
}
在routes.php文件中添加'png'扩展名后:
Router::extensions(['jpeg','gif','png']);
我在Mozilla中收到错误消息:
"NetworkError: 500 Internal Server Error - http://.../cakephp/images/profilePicture".
并且没有显示'jpeg'图像。但它在Chrome中运行良好。
任何帮助将不胜感激!
答案 0 :(得分:0)
问题是在routers.php文件中添加扩展名。它们已经存在于" vendor / cakephp / cakephp / src / Validation / Validation.php"文件。