當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HttpSocket::setContentResource方法代碼示例

本文整理匯總了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';
 }
開發者ID:laiello,項目名稱:double-l-bookmanagement,代碼行數:16,代碼來源:IsbnfuncComponent.php

示例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);
         }
     }
 }
開發者ID:simaostephanie,項目名稱:Cloggy,代碼行數:58,代碼來源:ImportWordPress.php


注:本文中的HttpSocket::setContentResource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。