本文整理汇总了PHP中Kurogo::tempFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Kurogo::tempFile方法的具体用法?PHP Kurogo::tempFile怎么用?PHP Kurogo::tempFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kurogo
的用法示例。
在下文中一共展示了Kurogo::tempFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retrieveResponse
protected function retrieveResponse()
{
if (!class_exists('ZipArchive')) {
throw new KurogoException("class ZipArchive (php-zip) not available");
}
$tmpFile = Kurogo::tempFile();
// this is the same as parent
if (!($this->requestURL = $this->url())) {
throw new KurogoDataException("URL could not be determined");
}
$this->requestParameters = $this->parameters();
// the following are private functions in URLDataRetriever
//$this->requestMethod = $this->setContextMethod();
//$this->requestHeaders = $this->setContextHeaders();
//$this->requestData = $this->setContextData();
Kurogo::log(LOG_INFO, "Retrieving {$this->requestURL}", 'url_retriever');
// the creation of $data is different from parent
copy($this->requestURL, $tmpFile);
$zip = new ZipArchive();
$zip->open($tmpFile);
$data = $zip->getFromIndex(0);
unlink($tmpFile);
// this is the same as parent
$http_response_header = isset($http_response_header) ? $http_response_header : array();
$response = $this->initResponse();
$response->setRequest($this->requestMethod, $this->requestURL, $this->requestParameters, $this->requestHeaders, null);
$response->setResponse($data);
$response->setResponseHeaders($http_response_header);
Kurogo::log(LOG_DEBUG, sprintf("Returned status %d and %d bytes", $response->getCode(), strlen($data)), 'url_retriever');
return $response;
}
示例2: retrieveResponse
protected function retrieveResponse()
{
$response = $this->initResponse();
if (strpos($this->fileStem, '.zip') !== false) {
if (!class_exists('ZipArchive')) {
throw new KurogoException("class ZipArchive (php-zip) not available");
}
$response->setContext('zipped', true);
$zip = new ZipArchive();
if (strpos($this->fileStem, 'http') === 0 || strpos($this->fileStem, 'ftp') === 0) {
$tmpFile = Kurogo::tempFile();
copy($this->fileStem, $tmpFile);
$zip->open($tmpFile);
} else {
$zip->open($this->fileStem);
}
// locate valid shapefile components
$shapeNames = array();
for ($i = 0; $i < $zip->numFiles; $i++) {
if (preg_match('/(.+)\\.(shp|dbf|prj)$/', $zip->getNameIndex($i), $matches)) {
$shapeName = $matches[1];
$extension = $matches[2];
if (!isset($shapeNames[$shapeName])) {
$shapeNames[$shapeName] = array();
}
$shapeNames[$shapeName][] = $extension;
}
}
$responseData = array();
foreach ($shapeNames as $shapeName => $extensions) {
if (in_array('dbf', $extensions) && in_array('shp', $extensions)) {
$fileData = array('dbf' => $zip->getFromName("{$shapeName}.dbf"), 'shp' => $zip->getFromName("{$shapeName}.shp"));
if (in_array('prj', $extensions)) {
$prjData = $zip->getFromName("{$shapeName}.prj");
$fileData['projection'] = new MapProjection($prjData);
}
$responseData[$shapeName] = $fileData;
}
}
$response->setResponse($responseData);
} elseif (realpath_exists("{$this->fileStem}.shp") && realpath_exists("{$this->fileStem}.dbf")) {
$response->setContext('zipped', false);
$response->setContext('shp', "{$this->fileStem}.shp");
$response->setContext('dbf', "{$this->fileStem}.dbf");
if (realpath_exists("{$this->fileStem}.prj")) {
$prjData = file_get_contents("{$this->fileStem}.prj");
$response->setContext('projection', new MapProjection($prjData));
}
} else {
throw new KurogoDataException("Cannot find {$this->fileStem}");
}
return $response;
}
示例3: retrieveResponse
protected function retrieveResponse()
{
if (!class_exists('ZipArchive')) {
throw new KurogoException("class ZipArchive (php-zip) not available");
}
$tmpFile = Kurogo::tempFile();
// this is the same as parent
if (!($this->requestURL = $this->url())) {
throw new KurogoDataException("URL could not be determined");
}
Kurogo::log(LOG_INFO, "Retrieving {$this->requestURL}", 'url_retriever');
// get data from parent request and save to temp file which we will
// unzip and return
$response = parent::retrieveResponse();
file_put_contents($tmpFile, $response->getResponse());
$zip = new ZipArchive();
if (!$zip->open($tmpFile)) {
throw new KurogoDataException("Could not open zip file");
}
$targetFile = $this->targetFile();
if ($targetFile) {
$index = $zip->locateName($targetFile);
} else {
$index = 0;
}
if ($index === false) {
// $zip->locateName failed
throw new KurogoDataException("Could not locate {$this->targetFile} in zip archive");
}
$data = $zip->getFromIndex($index);
unlink($tmpFile);
$zip->close();
$response->setResponse($data);
Kurogo::log(LOG_DEBUG, sprintf("Returned status %d and %d bytes", $response->getCode(), strlen($data)), 'url_retriever');
return $response;
}
示例4: retrieveData
protected function retrieveData($url)
{
if (strpos($url, '.kmz') !== false) {
if (!class_exists('ZipArchive')) {
throw new KurogoException("class ZipArchive (php-zip) not available");
}
$tmpFile = Kurogo::tempFile();
copy($url, $tmpFile);
$zip = new ZipArchive();
$zip->open($tmpFile);
$contents = $zip->getFromIndex(0);
unlink($tmpFile);
return $contents;
// this is false on failure, same as file_get_contents
}
return parent::retrieveData($url);
}