簡體   English   中英

如何檢查文件中的webroot目錄中是否存在文件?

[英]How to check if a file exists in webroot directory in cake?

我正在嘗試檢查webroot目錄中是否存在文件。 我正在使用file_exists但是我遇到了windows / linux文件路徑的問題。

$file = WWW_ROOT . 'img/uploads/file123.jpg';

file_exists($file);  //false

'$ windows上的文件:

C:\xampp\htdocs\blah\app\webroot/img/uploads/file123.jpg

'unix上的$ file:

/home/blah/webroot/img/uploads/file123.jpg

有沒有辦法檢查是否存在適用於兩個系統的文件? 我可以檢查系統和str_replace斜杠但也許有更好的方法?

有一個常量稱為DS (目錄分隔符)

試試吧

$file = WWW_ROOT . 'img' . DS . 'uploads' . DS . 'file123.jpg';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM