Description: Currently is authorized to obtain the visitor's avatar address, and saved in the database, the foreground when used by the address display.
Although visitors try to update their nickname and Avatar address every time they visit the home page, their avatar cannot be displayed when the visitor modifies the avatar until the page is accessed again.
Want to be able to save their avatar to the database, directly called, to avoid the above situation.
The avatar can be opened smoothly in the browser, but it cannot be obtained either through curl or get_file_contents ().
Reply to discussion (solution)
have done mobile phone and microblogging login interface
They provide a picture address that can be file_get_contents ()
Then directly file_put_content () is saved in the local folder, as the path and naming rules are set by themselves
Saving a remote picture should encapsulate a function
Then save the local path on the server
function Put_file_from_url_content ($url, $saveName, $path) {
Set run time to unlimited
Set_time_limit (0);
$url = Trim ($url);
$curl = Curl_init ();
Set the URL you need to crawl
curl_setopt ($curl, Curlopt_url, $url);
Set Header
curl_setopt ($curl, Curlopt_header, 1);
Sets the curl parameter, which requires the result to be saved to a string or output to the screen.
curl_setopt ($curl, Curlopt_returntransfer, 1);
Run Curl, request a Web page
$file = curl_exec ($curl);
Close URL Request
Curl_close ($curl);
Write a file to the obtained data
$filename = $path. $saveName;
$write = @fopen ($filename, "w");
if ($write = = False) {
return false;
}
if (fwrite ($write, $file) = = False) {
return false;
}
if (fclose ($write) = = False) {
return false;
}
}
Put_file_from_url_content ($userAvatar, $userOpenId. ". JPG ", $avatarPath);