public function process($files) { if ($files instanceof \Zend\Stdlib\Parameters) { $files = $files->toArray(); } // Make sure a proper array of files has been provided if (!is_array($files)) { throw new \Exception('Invalid files array provided'); } $destination = $this->options['destination']; // Make sure there is a destination set for the files if (empty($destination)) { throw new \Exception('Invalid file destination specified'); } if (!is_writable($destination . $this->options['path'])) { throw new \Exception('Unable to write to destination'); } $paths = array(); foreach ($files as $key => $info) { $name = $this->options['path']; if ($this->options['unique_prefix']) { $name = uniqid($name, true); } $name .= '_' . $info['name']; $rename = new RenameFilter(array('source' => $info['tmp_name'], 'target' => $destination . $name, 'overwrite' => $this->options['overwrite'])); $rename->filter($info['tmp_name']); $paths[$key] = $name; } return $paths; }
public function savePage(Page $page, $file) { $filetmpstr = $file['filepath']['tmp_name']; $filedir = $page->getPageID(); $tmpuppcontentpath = 'public/tmpuppcontent.txt'; $handle = fopen($tmpuppcontentpath, "w"); $note = $page->getPcontent(); if (fwrite($handle, $note) == false) { echo "写入文件失败"; } if (!fclose($handle)) { echo "failed in close"; } //重命名pcontent文件,之所以存进txt为了倒排。 $filter = new \Zend\Filter\File\Rename(array("target" => "public/data/post/" . $filedir . "/pcontent.txt", "randomize" => true)); $filter->filter($tmpuppcontentpath); //重命名上传文件 $suffilter = new BaseName(); $suffixname = $suffilter->filter($file['filepath']['name']); $basepath = WBasePath::getBasePath(); //public $filter = new \Zend\Filter\File\Rename(array("target" => $basepath . '/' . "data/post/" . $filedir . "/" . $suffixname, "randomize" => true)); $filepath = $filter->filter($filetmpstr); $filepath = substr($filepath, strlen($basepath)); $page->setFilepath($filepath); // print_r($page); // Debug::dump($page); // 数据库处理 $this->pageMapper->save($page); }
public function indexAction() { WAuthUtil::whetherLogout($this); $routeID = $this->params()->fromRoute('id'); $auth = WAuthUtil::get_auth(); $userID = $auth == null ? 0 : $auth->userID; $mode = $routeID == $userID ? self::User_EDIT : self::USER_CHECK; //处理上传头像请求 $request = $this->getRequest(); $user = $this->getservice()->getUser($routeID); if ($request->isPost() && $_FILES["faceimgpath"]["error"] == 0) { $upfilepath = $_FILES["faceimgpath"]["tmp_name"]; // Debug::dump($_FILES["faceimgpath"]["tmp_name"]); //http://framework.zend.com/manual/current/en/modules/zend.filter.file.html $basepath = WBasePath::getBasePath(); //public $filter = new Rename(array("target" => $basepath . '/' . "data/face/face.jpg", "randomize" => true)); $filepath = $filter->filter($upfilepath); // public/,,, $filepath = substr($filepath, strlen($basepath)); // File has been renamed to "./data/uploads/newfile_4b3403665fea6.txt" $user->setFaceimgpath($filepath); // Debug::dump($filepath); $this->getservice()->updateUser($user); } WAuthUtil::addUserpanelToLayout($this, '/account/' . $routeID); return new ViewModel(array('mode' => $mode, 'user' => $user, 'friends' => $this->getservice()->getSimi())); }
/** * {@inheritDoc} */ public function filter($value) { if (is_array($value)) { $this->setSource($value); } return parent::filter($value); }
public function saveRecruit(Recruit $recruit) { $filedir = $recruit->getRecruitID(); $tmpuppcontentpath = 'public/tmpuprcontent.txt'; $handle = fopen($tmpuppcontentpath, "w"); $note = $recruit->getRcontent(); if (fwrite($handle, $note) == false) { echo "写入文件失败"; } if (!fclose($handle)) { echo "failed in close"; } //重命名pcontent文件,之所以存进txt为了倒排。 $filter = new \Zend\Filter\File\Rename(array("target" => "public/data/recruit/" . $filedir . "/rcontent.txt", "randomize" => true)); $filter->filter($tmpuppcontentpath); // print_r($recruit); // Debug::dump($recruit); // 数据库处理 $this->recruitMapper->save($recruit); }
/** * @param ImageResourceInterface $resource * @return boolean */ public function persist(ImageResourceInterface $resource) { $ext = $resource->getExt(); $baseName = $resource->getToken() . ($ext ? '.' . $ext : ''); $target = realpath($this->options->getImagePersistentPath()) . '/' . $baseName; $moveUploadedFilter = new Rename(array('target' => $target, 'overwrite' => false, 'randomize' => false)); $moveUploadedFilter->filter($resource->getPath()); $resource->setPath($target); $result = file_exists($target); if ($result) { $result = chmod($target, 0664); } $resource->setHttpPath($this->options->getImageHttpPath() . '/' . $baseName); $this->setCallbacks(null, function () use($target) { if (file_exists($target)) { unlink($target); } }); return $result; }
public function addUpPicSerAction() { $path_for_route = "/data/postinlineimg/"; //由于在apache配置文件里设置到了public,注意前面的/一定要加,表示绝对路径 $path_for_frame = WBasePath::getBasePath() . "/" . $path_for_route; //实际存的时候存放的地址。 // if (file_exists($path. $_FILES["upload"]["name"])) // { // echo $_FILES["upload"]["name"] . " already exists please choose another image."; // } // $ran_path_for_route=$this->getservice()->getRandomizedname(); // $suffixfilter=new BaseName(); // $suffixname=$suffixfilter->filter($_FILES['upload']['name']);//upload name $filter = new Rename(array("target" => $path_for_frame . $_FILES["upload"]["name"], "randomize" => true)); $filepath = $filter->filter($_FILES['upload']['tmp_name']); $suffixfilter = new BaseName(); $suffixname = $suffixfilter->filter($filepath); // move_uploaded_file($_FILES["upload"]["tmp_name"], // $path_for_frame . $_FILES["upload"]["name"]); // echo "Stored in: " . $path_for_frame . $_FILES["upload"]["name"]; // Required: anonymous function reference number as explained above. $funcNum = $_GET['CKEditorFuncNum']; // Optional: instance name (might be used to load a specific configuration file or anything else). $CKEditor = $_GET['CKEditor']; // Optional: might be used to provide localized messages. $langCode = $_GET['langCode']; // Check the $_FILES array and save the file. Assign the correct path to a variable ($url). $url = $path_for_route . $suffixname; // Usually you will only assign something here if the file could not be uploaded. $message = ''; echo "<script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}', '{$message}');</script>"; $viewfordisable = new ViewModel(); $viewfordisable->setTerminal(true); //disable layout return $viewfordisable; }