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 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; }