php - Symfony - Get root directory path from custom class -
i declare new class not inherit controller
. now, want pull images remote path, , store them in directory. how root path?
class userinfo { public function getuseravatar($url) { $curl = curl_init(); curl_setopt($curl, curlopt_url, $this->m_avatarorigin); // $this->m_avatarorigin remote path pull user avatar. curl_setopt($curl, curlopt_returntransfer, 1); curl_setopt($curl, curlopt_header, true); curl_setopt($curl, curlopt_nobody, false); $response = curl_exec($curl); $header = ''; $body = ''; if (curl_getinfo($curl, curlinfo_http_code) == '200') { $headersize = curl_getinfo($curl, curlinfo_header_size); $header = substr($response, 0, $headersize); $body = substr($response, $headersize); } curl_close($curl); $filename = root_path."/../resources/avatar/".$this->m_name.".jpg"; // want "root_path" file_put_content($filename, $body); }
this class doesn't inherit controller
, cannot use function:
$this->get('kernel')->getrootdir();
is there better way let me root directory path?
Comments
Post a Comment