doutu2017 2016-11-01 21:48
浏览 38
已采纳

如果命令无法使用额外条件

Hi everyone im back with a new problem I have no idea why this is not working...

Ok this is my IF command

if(file_exists(__DIR__."/uploads/json_".$hash) &&
filesize(__DIR__."/uploads/json_".$hash) > 100 &&
time()-filemtime(__DIR__."/uploads/json_".$hash) < 168 * 3600 ===FALSE)

What I am trying to do is....A) check if the file exists and is over 100bytes and not older then a week...

I really need a inline solution as I have to do a find and replace in notepad as I have this in a few places in my script

Any help would be great

Ok here is the full code ignore the ##url## and ##key## with my last group attempt

$hash = hash("sha1","##key##");

if(file_exists(__DIR__."/uploads/json_".$hash) && (filesize(__DIR__."/uploads/json_".$hash) > 100) && (time()-filemtime(__DIR__."/uploads/json_".$hash) < 168 * 3600)){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "###URL###");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    $credits = curl_exec($ch);
    curl_close($ch);

    $f = fopen(__DIR__."/uploads/json_".$hash,"wb");
    fwrite($f,$credits);
    fclose($f);
        echo "
<script>

   alert(\"Updated Record\");

</script>";
    }else {
        $credits = file_get_contents(__DIR__."/uploads/json_".$hash);   
    }

$creditsun= json_decode($credits, true); // Decode the results into an array
  • 写回答

1条回答 默认 最新

  • druzuz321103 2016-11-01 21:54
    关注

    Remove === FALSE at the end?

    if (file_exists(__DIR__."/uploads/json_".$hash) && 
           filesize(__DIR__."/uploads/json_".$hash) > 100 && 
           time()-filemtime(__DIR__."/uploads/json_".$hash) < 168 * 3600) {
    // do stuff here
    }
    

    EDIT:

    the negation is obtained by placing ! on the front of the entire condition :

    if (!(file_exists(__DIR__."/uploads/json_".$hash) && 
           filesize(__DIR__."/uploads/json_".$hash) > 100 && 
           time()-filemtime(__DIR__."/uploads/json_".$hash) < 168 * 3600)) {
    // do stuff here
    }
    

    EDIT2:

    Have a look at this php manual page Logical Operators

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)