0

我有一个类似的问题,当我从 mysql 拉回一个值时,当我将它与文件名进行比较时,它总是返回 -6。只有当我从 mysql 中提取信息时才会发生这种情况

path rp_suzrl250.jpg strFile rp_suzrl250.jpg  
strcmp value -6 



path 2009_Evo.jpg strFile 2009_Evo.jpg  
strcmp value -6  

path DSCF6495.JPG strFile DSCF6495.JPG  
strcmp value -6
    $strFile = $dbrow[bikepicture]; 
    if($dh = opendir($file)){
        while(($path = readdir($dh)) !== false){
            $path = (string)$path;
            $strFile = (string)$strFile;
            echo "filename:  " . $path . "  " . strcmp($path, $strFile) . "<br>";
            if ($path ===  $strFile){
                echo $path . " got here " . "<br />";
            }
        }
    }
    if (strtoupper($path) === strtoupper($strFile)){  }

转换为字符串失败并转到上层失败。它返回-6。

4

1 回答 1

0

我的“答案”仅包含问题,但它们可能会引导您找到解决方案。

你的 $strFile 是一个字符串吗?你用 var_dump($strFile) 得到了什么?我假设您的代码片段进入了这种循环:

$results = $cnn->query($query);
while ($dbrow = $results->fetch_array(MYSQLI_ASSOC)) {
    ...
}

如果正确,您应该使用 $strFile = $dbrow['bikepicture'],否则bikepicture 将被解释为常量。顺便说一句,您不会收到警告/错误吗?

于 2013-09-30T22:48:12.900 回答