本文整理汇总了PHP中HttpSocket::setContentResource方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpSocket::setContentResource方法的具体用法?PHP HttpSocket::setContentResource怎么用?PHP HttpSocket::setContentResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpSocket
的用法示例。
在下文中一共展示了HttpSocket::setContentResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveImage
public function saveImage($isbn = null, $url = null)
{
if ($isbn == null || $url == null || $url == '') {
return false;
}
$http = new HttpSocket();
try {
$f = fopen(WWW_ROOT . 'img' . DS . 'books' . DS . $isbn . '.png', 'w');
$http->setContentResource($f);
$http->get($url);
fclose($f);
} catch (Exception $e) {
return false;
}
return 'books/' . $isbn . '.png';
}
示例2: __download_attachments
private function __download_attachments()
{
//get HttpSocket
App::uses('HttpSocket', 'Network/Http');
//get Folder
App::uses('Folder', 'Utility');
//get user id
$userId = AuthComponent::user('id');
foreach ($this->__attachments as $attachment) {
//generate Post model
$Post = ClassRegistry::init('CloggyBlogPost');
//generate Media model
$Media = ClassRegistry::init('CloggyBlogMedia');
$postId = '';
foreach ($this->__posts as $post) {
if ($attachment['post_id'] == $post['post_id']) {
$detailPost = $Post->getPostIdByTitle($post['title']);
if ($detailPost) {
$postId = $detailPost['CloggyNodeSubject']['node_id'];
break;
}
}
}
/*
* only if post id is not empty
*/
if (!empty($postId)) {
/*
* generate data
*/
$imageUrl = $attachment['url'];
$exp = explode('.', $imageUrl);
$ext = end($exp);
$filename = $attachment['title'] . '.' . $ext;
$path = APP . 'Plugin' . DS . 'Cloggy' . DS . 'webroot' . DS . 'uploads' . DS . 'CloggyBlog' . DS . 'images' . DS . $postId . DS;
$filepath = $path . $filename;
/*
* create folder
*/
$dir = new Folder();
$dir->create($path);
/*
* download atttachment
*/
$http = new HttpSocket();
$f = fopen($filepath, 'w+');
$http->setContentResource($f);
$results = $http->get($imageUrl);
fclose($f);
/*
* save image
*/
$mediaId = $Media->setImage($userId, array('media_file_type' => $results->getHeader('Content-Type'), 'media_file_location' => DS . 'uploads' . DS . 'CloggyBlog' . DS . 'images' . DS . $postId . DS . $filename));
//save new image
$Media->setPostAttachment($postId, $mediaId);
}
}
}