由于路径,图像类函数无法正常工作


Image Class Function not working correctly due to path

我正在使用以下函数:

  class Image {
    static function url($id, $type = 'maps') {
        $path = UPLOAD_DIRECTORY . '/' . $type . '/';
        $files = glob($path . $id . '.*');
        if (count($files)) {
            $ext = substr($files[0], strpos($files[0], '.') - strlen($files[5]));
            return SERVER_URL . 'img/' . $type . '/' . $id . $ext;
        } else {
            return '';
        }
    }
}

当托管在WAMP上时,它可以正常工作,但是当在nginx上运行的Unix上使用时,由于文件路径的原因,它无法正确显示图像。它似乎在URL中添加了文件的物理路径,因此它认为文件的补丁是 http://localhost/demo/img/maps/20/public_html/demo/img/maps/20.png

在 WAMP 上,它正确显示,即 URL 已 http://localhost/demo/img/maps/20.png

这些是定义的变量:

define('SERVER_URL', 'http://localhost/demo/');
define('UPLOAD_DIRECTORY', dirname(__FILE__) . '/img');

id=20;

图像的物理位置位于/public_html/demo/img/maps/中

如何在 unix 操作系统上解决此问题。

设法

制定了解决方案(顺便说一句,我不是程序员)。

基本上在 UNIX 服务器上,图像所在的目录在路径中有一个点,而在 wamp 上则没有。

所以我要做的是使用 strrpost 而不是 strpost - 这找到字符串中子字符串最后一次出现的位置,而不是第一次出现的位置。