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


PHP LocalFile::getSize方法代码示例

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


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

示例1: execute

 function execute($par)
 {
     global $wgOut, $wgUser, $wgRequest;
     global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     if ($wgUser->getID() == 0) {
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     if (!in_array('staff', $wgUser->getGroups())) {
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     $this->errorFile = "";
     $this->errorTitle = "";
     if ($wgRequest->getVal('delete')) {
         $wgOut->setArticleBodyOnly(true);
         $hpid = str_replace('delete_', '', $wgRequest->getVal('delete'));
         $html = self::deleteHPImage($hpid);
         $wgOut->addHTML($html);
         return;
     }
     $this->postSuccessful = true;
     if ($wgRequest->wasPosted()) {
         if ($wgRequest->getVal("updateActive")) {
             $dbw = wfGetDB(DB_MASTER);
             //first clear them all
             $dbw->update(WikihowHomepageAdmin::HP_TABLE, array('hp_active' => 0, 'hp_order' => 0), '*', __METHOD__);
             $images = $wgRequest->getArray("hp_images");
             $count = 1;
             foreach ($images as $image) {
                 if (!$image) {
                     continue;
                 }
                 $dbw->update(WikihowHomepageAdmin::HP_TABLE, array('hp_active' => 1, 'hp_order' => $count), array('hp_id' => $image));
                 $count++;
             }
         } else {
             $title = WikiPhoto::getArticleTitleNoCheck($wgRequest->getVal('articleName'));
             if (!$title->exists()) {
                 $this->postSuccessful = false;
                 $this->errorTitle = "* That article does not exist.";
             }
             if ($this->postSuccessful) {
                 //keep going
                 $imageTitle = Title::newFromText($wgRequest->getVal('wpDestFile'), NS_IMAGE);
                 $file = new LocalFile($imageTitle, RepoGroup::singleton()->getLocalRepo());
                 $file->upload($wgRequest->getFileTempName('wpUploadFile'), '', '');
                 $filesize = $file->getSize();
                 if ($filesize > 0) {
                     $dbw = wfGetDB(DB_MASTER);
                     $dbw->insert(WikihowHomepageAdmin::HP_TABLE, array('hp_page' => $title->getArticleID(), 'hp_image' => $imageTitle->getArticleID()));
                     $article = new Article($imageTitle);
                     $limit = array();
                     $limit['move'] = "sysop";
                     $limit['edit'] = "sysop";
                     $protectResult = $article->updateRestrictions($limit, "Used on homepage");
                 } else {
                     $this->postSuccessful = false;
                     $this->errorFile = "* We encountered an error uploading that file.";
                 }
             }
         }
     }
     $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
     $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
     $adc = wfBoolToStr($useAjaxDestCheck);
     $alp = wfBoolToStr($useAjaxLicensePreview);
     $wgOut->setPageTitle('WikiHow Homepage Admin');
     $wgOut->addScript("<script type=\"text/javascript\">\nwgAjaxUploadDestCheck = {$adc};\nwgAjaxLicensePreview = {$alp};\n</script>");
     $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('jquery-ui-1.8.custom.min.js'), 'extensions/wikihow/common/ui/js', false));
     $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('wikihowhomepageadmin.js'), 'extensions/wikihow/homepage', false));
     $wgOut->addScript(HtmlSnips::makeUrlTags('css', array('wikihowhomepageadmin.css'), 'extensions/wikihow/homepage', false));
     $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('upload.js'), 'skins/common', false));
     $this->displayHomepageData();
     $this->displayForm();
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:82,代码来源:WikihowHomepageAdmin.body.php

示例2: 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

示例3: testGetSize

 public function testGetSize()
 {
     $this->assertNotEquals(0, $this->fixture_file->getSize());
     $this->assertEquals(filesize(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'), $this->fixture_file->getSize());
     $myNonExistingFile = new LocalFile(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile2.ext');
     $this->assertEquals(0, $myNonExistingFile->getSize());
 }
开发者ID:DavidGarciaCat,项目名称:eyeos,代码行数:7,代码来源:LocalFileTest.php

示例4: getSize

 /**
  * @return int The size of the file (in KB)
  */
 public function getSize($recursive = false)
 {
     $this->checkReadPermission();
     return parent::getSize($recursive);
 }
开发者ID:DavidGarciaCat,项目名称:eyeos,代码行数:8,代码来源:LocalFile.php


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