当前位置: 首页>>代码示例>>PHP>>正文


PHP LocalFile::getMediaType方法代码示例

本文整理汇总了PHP中LocalFile::getMediaType方法的典型用法代码示例。如果您正苦于以下问题:PHP LocalFile::getMediaType方法的具体用法?PHP LocalFile::getMediaType怎么用?PHP LocalFile::getMediaType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LocalFile的用法示例。


在下文中一共展示了LocalFile::getMediaType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: uploadImage

 /**
  * Accept a request to upload an image either via POST data (user upload)
  * or via flickr or google / wikimedia.org search.
  *
  * @param $src string with value 'upload', 'flickr' or 'wiki'
  * @return html outputs image details page
  */
 private function uploadImage($src)
 {
     global $wgRequest, $wgUser, $IP, $wgOut;
     $error = '';
     $debugInfo = array();
     if ($src == 'upload') {
         $tempname = self::createTempFilename();
         $tempUser = self::getTempFileUser();
         $file = new LocalFile(Title::newFromText($tempname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
         $name = $wgRequest->getFileName('wpUploadFile');
         $comment = '';
         $file->upload($wgRequest->getFileTempName('wpUploadFile'), $comment, '', 0, false, false, $tempUser);
         $filesize = $file->getSize();
         if (!$filesize) {
             $error = wfMsg('eiu-upload-error');
         }
     } elseif ($src == 'flickr' || $src == 'wiki') {
         $sourceName = $src == 'flickr' ? 'Flickr' : 'Mediawiki Commons';
         $tempname = self::createTempFilename();
         $file = new LocalFile(Title::newFromText($tempname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
         $details = (array) json_decode($wgRequest->getVal('img-details'));
         $name = $details['name'];
         // scrape the file using curl
         $filename = '/tmp/tmp-curl-' . mt_rand(0, 100000000) . '.jpg';
         $remoteFile = strlen($details['url_l']) ? $details['url_l'] : $details['url'];
         $ch = curl_init($remoteFile);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         $fp = fopen($filename, 'w');
         curl_setopt($ch, CURLOPT_FILE, $fp);
         $ret = curl_exec($ch);
         $err = curl_error($ch);
         curl_close($ch);
         fclose($fp);
         if ($err) {
             $debugInfo['curl'] = $err;
         }
         $filesize = @filesize($filename);
         if ($filesize) {
             if ($src == 'flickr' || preg_match('@^http://[^/]*flickr@', $details['url'])) {
                 require_once $IP . '/extensions/3rdparty/phpFlickr-2.3.1/phpFlickr.php';
                 $flickr = new phpFlickr(WH_FLICKR_API_KEY);
                 $photo = $flickr->photos_getInfo($details['photoid']);
                 $err = $flickr->getErrorMsg();
                 if ($err) {
                     $debugInfo['flickrAPI'] = $err;
                 }
                 $license = $photo['license'];
                 $username = $photo['owner']['username'];
                 $comment = '{{flickr' . intval($license) . '|' . wfEscapeWikiText($details['photoid']) . '|' . wfEscapeWikiText($details['ownerid']) . '|' . wfEscapeWikiText($username) . '}}';
             } else {
                 $comment = self::getWPLicenseTag($details['url']);
             }
             // finish initializing the $file obj
             $tempUser = self::getTempFileUser();
             $status = $file->upload($filename, '', '', 0, false, false, $tempUser);
             if (!$status->ok) {
                 $error = wfMsg('eiu-upload-error');
             }
         } else {
             $error = wfMsg('eiu-download-error', $sourceName);
         }
     }
     if ($error) {
         $html = EasyTemplate::html('eiu_file_error.tmpl.php', array('error' => $error));
         $wgOut->addHTML($html);
         error_log("file from {$src} error msgs: " . print_r($debugInfo, true));
     } else {
         $mwname = $tempname;
         $props = array('src' => $src, 'name' => $name, 'mwname' => $mwname, 'is_image' => $file->getMediaType() == 'BITMAP' || $file->getMediaType() == 'DRAWING', 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'upload_file' => $file, 'image_comment' => $comment, 'license' => $wgUser->getOption('image_license'), 'file' => $file);
         $html = EasyTemplate::html('eiu_image_details.tmpl.php', $props);
         $wgOut->addHTML($html);
     }
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:81,代码来源:Easyimageupload.body.php


注:本文中的LocalFile::getMediaType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。