Gdal provides an interface to access network data, the specific help documentation can access here (http://gdal.org/cpl__http_8h.html ). However, the premise is that gdal needs to rely on a third-party open-source library libcurl. The main function of libcurl is to use different protocols to connect and communicate with different servers ~ That is to say, sockphp supports libcurl (which allows you to connect to and communicate with different servers using different protocols )., Libcurl currently supports HTTP, https, FTP, Gopher, telnet, dict, file, and LDAP protocols. Libcurl also supports HTTPS certificate authorization, http post, http put, FTP upload (of course, you can also use php ftp extension), HTTP basic form upload, proxy, cookies, and user authentication.
For details, visit libcurl's Wikipedia. The link is here.
Well, the following describes how to use it. First, use the cplhttpenabled () function to check whether gdal supports libcurl, and then use the following code to obtain the URL returned information. (The following URL is the profile picture URL of my blog ).
CPLHTTPResult *pRest = CPLHTTPFetch ("http://avatar.csdn.net/7/0/7/1_liminlu0314.jpg", NULL);
Then, it is determined that the release of Prest is null. If it is not null, the information is obtained successfully and the obtained information is stored in prest. Then retrieve the content from the prest. The following is a small function encapsulated by me that can be used to obtain images or files from the network and store them locally.
bool SaveUrl2File(const char* pszUrl, const char* pszFileName){if( CPLHTTPEnabled() != TRUE)return false;CPLHTTPResult *pRest = CPLHTTPFetch (pszUrl, NULL);if (pRest == NULL)return false;FILE *pFile = fopen(pszFileName, "wb");if (pFile == NULL)return false;fwrite( pRest->pabyData, sizeof( GByte ), pRest->nDataLen, pFile );fclose(pFile);CPLHTTPDestroyResult(pRest);CPLHTTPCleanup();return true;}
It is easy to use. For example, you can use the following code to download an image or mp3 file.
bool bIsSuccess = SaveUrl2File("http://avatar.csdn.net/7/0/7/1_liminlu0314.jpg", "C:\\photo.jpg");bIsSuccess = SaveUrl2File("http://music.charlottedann.com/songs/Safe%20And%20Sound.mp3", " Safe & Sound Taylor Swift mp3");
The above one is to download my csdn avatar, and the other is to download the ending song "Safe and sound" of "Hunger Game". ps, nice to listen to. I recommend it.