#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Need a expert to optimize function


    Hi, I am trying to code a function but I have trouble optimizing it. Is there anyone who can make this better?

    Thanks in advance for taking time and effort to read through this batch of code.
    PHP Code:
    function trytomakewritable($file){


        
    //IF NOT IS WRITABLE
        
    if( function_exists('intval') && function_exists('substr') && function_exists('decoct') && function_exists('fileperms') ){

            if( 
    intval(substr(decoctfileperms($file) ), 3)) < 600 ){
                if (
    function_exists('chmod') && !ini_get('safe_mode')){
                    if(!@
    chmod$file0644 )){

                        if(
    function_exists("chown") && function_exists("get_current_user")){

                            @
    chown($fileget_current_user());
                            if(!@
    chmod$file0644 ))
                                return 
    false;

                        }else{

                            return 
    false;

                        }

                    }

                } else
                    return 
    false;
            }

        }

        return 
    true;

  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,961
    Rep Power
    9397
    1. Don't try to write code for PHP 3. All those function_exists() calls are completely unnecessary.
    2. I doubt WordPress is running as root. chown() will fail.
    3. If you don't own the file (and aren't root) then chmod() will fail. If you do then it's highly unlikely, and should never be the case, that you can't write to it.
    4. Ergo the whole function is pointless.

    What's the situation where you think you need this?

IMN logo majestic logo threadwatch logo seochat tools logo