Wayne Allen Wayne Allen - 1 month ago 7
PHP Question

If command not working with extra conditions

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

Answer

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