Search code examples
phpcronfile-exists

running a php page via crontab and having issues with if file_exists


I have a question...I am running a php page daily through a crobtab and I seem to be getting erros when this code is run..

include(CLASS_PATH .'EmailAddressValidator.php');

so I applied this code...

if(file_exists('/var/www/testsite/classes/EmailAddressValidator.php')){
    include('/var/www/testsite/classes/EmailAddressValidator.php');
}else{
    include(CLASS_PATH .'EmailAddressValidator.php');
}

but I also have live site at

/var/www/livesite/classes/EmailAddressValidator.php

and its been a pain doing back and forth changing my code fromtestsite to livesite is there an easier way to do this..

I've tried..

if(file_exists('/var/www/testsite/classes/EmailAddressValidator.php')){
    include('/var/www/testsite/classes/EmailAddressValidator.php');
elseif(file_exists('/var/www/livesite/classes/EmailAddressValidator.php')){
    include('/var/www/livesite/classes/EmailAddressValidator.php');
}else{
    include(CLASS_PATH .'EmailAddressValidator.php');
}

Testing out all answers...will have a vote by monday end day


Solution

  • You can use relative paths instead

    ../classes/EmailAddressValidator.php
    

    or whatever the path is.