我在webfoot之外有一个文件夹,我正在使用$ this-> response->文件($ path);在里面显示图像。
当我传入文件名时,我的控制器代码工作正常。但我需要将其作为部分URL传递。这就是它破裂的地方。我曾尝试使用urldecode这仍然将其视为网址。
<?php echo ('<img src="books/sendFile/'.rawurlencode("38/backgrounds/orchard-left.png").'" width="100%" alt="aswq" />') ?>
输出为books / sendFile / 38%2Fbackgrounds%2Forchard-left.png但浏览器仍将其视为books / sendFile / 38 / backgrounds / orchard-left.png
我的控制器
public function sendFile($file) {
$file = rawurldecode($file);
$path = ROOT.DS.'bookUploads'.DS.'Users'.DS.'ingemit/Books/'.$file;
$this->response->file($path);
return $this->response;
}