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


PHP SPRequest::file方法代码示例

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


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

示例1: upload

 protected function upload()
 {
     $ident = SPRequest::cmd('ident', null, 'post');
     $data = SPRequest::file($ident, 'tmp_name');
     $secret = md5(Sobi::Cfg('secret'));
     if ($data) {
         $properties = SPRequest::file($ident);
         $fileName = md5(SPRequest::file($ident, 'name') . time() . $secret);
         $path = SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $fileName;
         /** @var $file SPFile */
         $file = SPFactory::Instance('base.fs.file');
         if (!$file->upload($data, $path)) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => ''));
         }
         $path = $file->getPathname();
         $type = $this->check($path);
         $properties['tmp_name'] = $path;
         SPFs::write($path . '.var', SPConfig::serialize($properties));
         $response = array('type' => 'success', 'text' => Sobi::Txt('FILE_UPLOADED', $properties['name'], $type), 'id' => 'file://' . $fileName, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size']));
     } else {
         $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => '');
     }
     //		$field = SPRequest::cmd( 'field', null );
     $this->message($response);
 }
开发者ID:pelloq1,项目名称:SobiPro,代码行数:25,代码来源:file.php

示例2: ProxyUpload

 /**
  * */
 public function ProxyUpload()
 {
     $ident = SPRequest::cmd('ident', null, 'post');
     $data = SPRequest::file($ident, 'tmp_name');
     $secret = md5(Sobi::Cfg('secret'));
     if ($data) {
         $properties = SPRequest::file($ident);
         $orgFileName = $properties['name'];
         $extension = SPFs::getExt($orgFileName);
         $orgFileName = str_replace('.' . $extension, '.' . strtolower($extension), $orgFileName);
         if ($properties['size'] > $this->maxSize) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $properties['size'], $this->maxSize), 'id' => ''));
         }
         $dirNameHash = md5($orgFileName . time() . $secret);
         $dirName = SPLoader::dirPath("tmp.files.{$secret}.{$dirNameHash}", 'front', false);
         SPFs::mkdir($dirName);
         $path = $dirName . $orgFileName;
         /** @var $file SPImage */
         $orgImage = SPFactory::Instance('base.fs.image');
         if (!$orgImage->upload($data, $path)) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => ''));
         }
         if (Sobi::Cfg('image_field.fix_rotation', true)) {
             if ($orgImage->fixRotation()) {
                 $orgImage->save();
             }
         }
         if ($this->crop) {
             $croppedImage = clone $orgImage;
             list($originalWidth, $originalHeight) = getimagesize($path);
             $aspectRatio = $this->resizeWidth / $this->resizeHeight;
             $width = $aspectRatio * $originalHeight > $originalWidth ? $originalWidth : $aspectRatio * $originalHeight;
             $height = $originalWidth / $aspectRatio > $originalHeight ? $originalHeight : $originalWidth / $aspectRatio;
             try {
                 $croppedImage->crop($width, $height);
                 $croppedImage->saveAs($dirName . 'cropped_' . $orgFileName);
                 $ico = SPFactory::Instance('base.fs.image', $dirName . 'cropped_' . $orgFileName);
             } catch (SPException $x) {
                 $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_CROP', $x->getMessage()), 'id' => ''));
             }
         } else {
             $ico = clone $orgImage;
         }
         $image = clone $orgImage;
         try {
             $previewSize = explode(':', Sobi::Cfg('image.preview_size', '500:500'));
             $image->resample($previewSize[0], $previewSize[1], false);
             $image->saveAs($dirName . 'resized_' . $orgFileName);
         } catch (SPException $x) {
             $image->delete();
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => ''));
         }
         try {
             $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80'));
             $ico->resample($icoSize[0], $icoSize[1], false);
             $ico->saveAs($dirName . 'icon_' . $orgFileName);
         } catch (SPException $x) {
             $ico->delete();
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => ''));
         }
         $path = $orgImage->getPathname();
         $type = $this->check($path);
         $properties['tmp_name'] = $path;
         SPFs::write(SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $orgFileName . '.var', SPConfig::serialize($properties));
         $response = array('type' => 'success', 'text' => $this->crop ? Sobi::Txt('IMAGE_UPLOADED_CROP', $properties['name'], $type) : Sobi::Txt('FILE_UPLOADED', $properties['name']), 'id' => 'directory://' . $dirNameHash, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size'], 'original' => $dirNameHash . '/' . $properties['name'], 'icon' => $dirNameHash . '/' . 'icon_' . $orgFileName, 'crop' => $this->crop, 'height' => $this->resizeHeight, 'width' => $this->resizeWidth));
     } else {
         $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => '');
     }
     $this->message($response);
 }
开发者ID:kishoreweblabs,项目名称:SobiPro,代码行数:72,代码来源:image.php

示例3: save

 public function save(&$attr)
 {
     static $lang = null;
     static $defLang = null;
     if (!$lang) {
         $lang = Sobi::Lang();
         $defLang = Sobi::DefLang();
     }
     $file = SPRequest::file('spfieldsopts', 'tmp_name');
     if ($file) {
         $data = parse_ini_file($file, true);
     } elseif (is_string($attr['options'])) {
         $data = parse_ini_string($attr['options'], true);
     } else {
         $data = null;
     }
     $options = $this->parseOptsFile($data);
     if (!count($options) && count($attr['options'])) {
         $p = 0;
         $hold = array();
         foreach ($attr['options'] as $o) {
             if (is_numeric($o['id'])) {
                 $o['id'] = $this->nid . '_' . $o['id'];
             }
             if (isset($o['id'])) {
                 $i = 0;
                 $oid = $o['id'];
                 while (isset($hold[$oid])) {
                     $oid = $o['id'] . '_' . ++$i;
                 }
                 $options[] = array('id' => $oid, 'name' => $o['name'], 'parent' => null, 'position' => ++$p);
                 $hold[$oid] = $oid;
             }
         }
     }
     if (count($options)) {
         unset($attr['options']);
         $optionsArr = array();
         $labelsArr = array();
         $defLabelsArr = array();
         $optsIds = array();
         foreach ($options as $i => $option) {
             /* check for doubles */
             foreach ($options as $pos => $opt) {
                 if ($i == $pos) {
                     continue;
                 }
                 if ($option['id'] == $opt['id']) {
                     $option['id'] = $option['id'] . '_' . substr((string) microtime(), 2, 8) . rand(1, 100);
                     SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID');
                 }
             }
             $optionsArr[] = array('fid' => $this->id, 'optValue' => $option['id'], 'optPos' => $option['position'], 'optParent' => $option['parent']);
             $defLabelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id);
             $labelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id);
             $optsIds[] = $option['id'];
         }
         /* @var SPdb $db */
         $db =& SPFactory::db();
         /* try to delete the existing labels */
         try {
             $db->delete('spdb_field_option', array('fid' => $this->id));
             $db->delete('spdb_language', array('oType' => 'field_option', 'fid' => $this->id, '!sKey' => $optsIds));
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_SELECTED_OPTIONS', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         /* insert new values */
         try {
             $db->insertArray('spdb_field_option', $optionsArr);
             $db->insertArray('spdb_language', $labelsArr, true);
             if ($defLang != $lang) {
                 $db->insertArray('spdb_language', $defLabelsArr, false, true);
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_STORE_FIELD_OPTIONS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     if (!isset($attr['params'])) {
         $attr['params'] = array();
     }
     $myAttr = $this->getAttr();
     $properties = array();
     if (count($myAttr)) {
         foreach ($myAttr as $property) {
             $properties[$property] = isset($attr[$property]) ? $attr[$property] : null;
         }
     }
     $attr['params'] = $properties;
     $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data);
 }
开发者ID:kishoreweblabs,项目名称:SobiPro,代码行数:90,代码来源:chbxgroup.php

示例4: save

 public function save(&$attr)
 {
     static $lang = null;
     static $defLang = null;
     if (!$lang) {
         $lang = Sobi::Lang();
         $defLang = Sobi::DefLang();
     }
     $file = SPRequest::file('spfieldsopts', 'tmp_name');
     if ($file) {
         $data = parse_ini_file($file, true);
     } elseif (is_string($attr['options'])) {
         $data = parse_ini_string($attr['options'], true);
     } else {
         $data = null;
     }
     $options = $this->parseOptsFile($data);
     if (!count($options) && count($attr['options'])) {
         $p = 0;
         $hold = array();
         foreach ($attr['options'] as $o) {
             if (is_numeric($o['id'])) {
                 $o['id'] = $this->nid . '_' . $o['id'];
             }
             if (isset($o['id'])) {
                 $i = 0;
                 $oid = $o['id'];
                 while (isset($hold[$oid])) {
                     $oid = $o['id'] . '_' . ++$i;
                 }
                 $options[] = array('id' => $oid, 'name' => $o['name'], 'parent' => null, 'position' => ++$p);
                 $hold[$oid] = $oid;
             }
         }
     }
     if (count($options)) {
         unset($attr['options']);
         $optionsArr = array();
         $labelsArr = array();
         $optsIds = array();
         $defLabelsArr = array();
         $duplicates = false;
         foreach ($options as $i => $option) {
             /* check for doubles */
             foreach ($options as $pos => $opt) {
                 if ($i == $pos) {
                     continue;
                 }
                 if ($option['id'] == $opt['id']) {
                     $option['id'] = $option['id'] . '_' . substr((string) microtime(), 2, 8) . rand(1, 100);
                     $duplicates = true;
                 }
             }
             $optionsArr[] = array('fid' => $this->id, 'optValue' => $option['id'], 'optPos' => $option['position'], 'optParent' => $option['parent']);
             $defLabelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id);
             $labelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id);
             $optsIds[] = $option['id'];
         }
         if ($duplicates) {
             SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID');
         }
         $db = SPFactory::db();
         /* try to delete the existing labels */
         try {
             $db->delete('spdb_field_option', array('fid' => $this->id));
             $db->delete('spdb_language', array('oType' => 'field_option', 'fid' => $this->id, '!sKey' => $optsIds));
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_STORE_FIELD_OPTIONS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         /* insert new values */
         try {
             $db->insertArray('spdb_field_option', $optionsArr);
             $db->insertArray('spdb_language', $labelsArr, true);
             if ($defLang != $lang) {
                 $db->insertArray('spdb_language', $defLabelsArr, false, true);
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_SELECTED_OPTIONS', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     if (!isset($attr['params'])) {
         $attr['params'] = array();
     }
     $myAttr = $this->getAttr();
     $properties = array();
     if (count($myAttr)) {
         foreach ($myAttr as $property) {
             $properties[$property] = isset($attr[$property]) ? $attr[$property] : null;
         }
     }
     $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data);
     /** handle upload of new definition file */
     $XMLFile = SPRequest::file('select-list-dependency', 'tmp_name');
     if ($XMLFile && file_exists($XMLFile)) {
         $XMLFileName = SPRequest::file('select-list-dependency', 'name');
         if (SPFs::getExt($XMLFileName) == 'zip') {
             $arch = SPFactory::Instance('base.fs.archive');
             $name = str_replace('.zip', null, $XMLFileName);
             $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
             $c = 0;
//.........这里部分代码省略.........
开发者ID:ranrolls,项目名称:ras-full-portal,代码行数:101,代码来源:select.php

示例5: install

 private function install($file = null)
 {
     $arch = SPFactory::Instance('base.fs.archive');
     $ajax = strlen(SPRequest::cmd('ident', null, 'post'));
     if (!$file && SPRequest::string('root')) {
         $file = str_replace('.xml', null, SPRequest::string('root'));
         $file = SPLoader::path('tmp.install.' . $file, 'front', true, 'xml');
     }
     if (!$file) {
         $ident = SPRequest::cmd('ident', null, 'post');
         $data = SPRequest::file($ident);
         $name = str_replace(array('.' . SPFs::getExt($data['name']), '.'), null, $data['name']);
         $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
         $c = 0;
         while (SPFs::exists($path)) {
             $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false);
         }
         /*
          * temp directory - will be removed later but it needs to be writable for apache and Joomla! fs (FTP mode)
          */
         try {
             if (Sobi::Cfg('ftp_mode')) {
                 SPFs::mkdir($path, 0777);
             } else {
                 SPFs::mkdir($path);
             }
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
         $file = $path . '/' . $data['name'];
         try {
             $arch->upload($data['tmp_name'], $file);
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     } elseif (SPRequest::string('root') && $file) {
         $path = dirname($file);
     } else {
         $arch->setFile($file);
         $name = str_replace(array('.' . SPFs::getExt($file), '.'), null, basename($file));
         $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
         $c = 0;
         while (SPFs::exists($path)) {
             $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false);
         }
         /*
          * temp directory - will be removed later but it needs to  writable for apache and Joomla! fs (FTP mode)
          */
         try {
             if (Sobi::Cfg('ftp_mode')) {
                 SPFs::mkdir($path, 0777);
             } else {
                 SPFs::mkdir($path);
             }
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     }
     if ($path) {
         if (!SPRequest::string('root')) {
             if (!$arch->extract($path)) {
                 return $this->ajaxResponse($ajax, SPLang::e('CANNOT_EXTRACT_ARCHIVE', basename($file), $path), false, SPC::ERROR_MSG);
             }
         }
         $dir =& SPFactory::Instance('base.fs.directory', $path);
         $xml = array_keys($dir->searchFile('.xml', false, 2));
         if (!count($xml)) {
             return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG);
         }
         $definition = $this->searchInstallFile($xml);
         if (!$definition) {
             if (SPFactory::CmsHelper()->installerFile($xml)) {
                 try {
                     $message = SPFactory::CmsHelper()->install($xml, $path);
                     return $this->ajaxResponse($ajax, $message['msg'], $ajax, $message['msgtype']);
                 } catch (SPException $x) {
                     return $this->ajaxResponse($ajax, $x->getMessage(), $ajax, SPC::ERROR_MSG);
                 }
             } else {
                 return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG);
             }
         }
         /** @var $installer SPInstaller */
         $installer =& SPFactory::Instance('services.installers.' . trim(strtolower($definition->documentElement->tagName)), $xml[0], trim($definition->documentElement->tagName));
         try {
             $installer->validate();
             $msg = $installer->install();
             return $this->ajaxResponse($ajax, $msg, true, SPC::SUCCESS_MSG);
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     } else {
         return $this->ajaxResponse($ajax, SPLang::e('NO_FILE_HAS_BEEN_UPLOADED'), false, SPC::ERROR_MSG);
     }
 }
开发者ID:kishoreweblabs,项目名称:SobiPro,代码行数:95,代码来源:extensions.php


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