AnsweredAssumed Answered

“move_uploaded_file” function not working in SugarCRM logic hook

Question asked by Sohan Tirpude on Sep 1, 2016
Latest reply on Sep 1, 2016 by sugar.dennis

I am trying to move uploaded files to new location using SugarCRM CE's logic hook either after_save or before_save. But I am unable to do so. Kindly find my logic hook code:


class attachment
    public function attachment(&$bean, $event, $arguments)
            $upload_dir = $GLOBALS['sugar_config']['upload_dir'];


            $target_file = $upload_dir . basename($_FILES["filename_new_file"]["name"]);


            if (move_uploaded_file($_FILES["filename_new_file"]["tmp_name"], $target_file))
                $GLOBALS['log']->fatal("The file has been uploaded");
                $GLOBALS['log']->fatal("Sorry, there was an error uploading your file.");


Here, when I print $_FILES, I am getting desired output:


    [name] => twitter.png
    [type] => image/png
    [tmp_name] => /tmp/php5wBmgK
    [error] => 0
    [size] => 203


Now I have seen many posts, where they mentioned solution for this is to make sure the correct file permission and file ownership. I tried that, but didn't work out.


Lastly, to remove the possibility of issue with file permission or file ownership, I made one file upload script and run that script outside of CRM and that time move_uploaded_file function worked as it should.


But when I try to achieve the same with the use of logic hook, I am unable to get desired output. Kindly guide me here.
file-upload logic hook move