[李景山php]每天laravel-20160911|FileSystem-2

來源:互聯網
上載者:User

標籤:yesterday   function   require   return   public   

   /**    * Get the returned value of a file.    *    * @param  string  $path    * @return mixed    *    * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException    */   public function getRequire($path)   {       if ($this->isFile($path)) {// if it is a file           return require $path; // require it       }       throw new FileNotFoundException("File does not exist at path {$path}");// throw Exception   }// yesterday we learn this filesystem function// now we will get the return value of a file.   /**    * Require the given file once.    *    * @param  string  $file    * @return mixed    */   public function requireOnce($file)   {       require_once $file;// fool   }// require once a wrap by function   /**    * Write the contents of a file.    *    * @param  string  $path    * @param  string  $contents    * @param  bool  $lock    * @return int    */   public function put($path, $contents, $lock = false)   {       return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);   }// use a put function to set a normal function// and determine a if has a file write lock   /**    * Prepend to a file.    *    * @param  string  $path    * @param  string  $data    * @return int    */   public function prepend($path, $data)   {       if ($this->exists($path)) {           return $this->put($path, $data.$this->get($path));       }// if has old data, get it and combine it and new data       return $this->put($path, $data);   }// prepend is like insert some thing before the old data.   /**    * Append to a file.    *    * @param  string  $path    * @param  string  $data    * @return int    */   public function append($path, $data)   {       return file_put_contents($path, $data, FILE_APPEND);   }// append can use this file_put_contents function and set this variable to get it.   /**    * Delete the file at a given path.    *    * @param  string|array  $paths    * @return bool    */   public function delete($paths)   {// use a very good way to delete a file ,but we need know this file path       $paths = is_array($paths) ? $paths : func_get_args();// if paths is a array       $success = true;// set this flag for done       foreach ($paths as $path) {// loop this path           try {               if (! @unlink($path)) {// delete the file                   $success = false;               }           } catch (ErrorException $e) {// catch some thing wrong               $success = false;           }       }       return $success;// return result;   }   /**    * Move a file to a new location.    *    * @param  string  $path    * @param  string  $target    * @return bool    */   public function move($path, $target)   {       return rename($path, $target);   }// a wrap like move use this rename


本文出自 “專註php” 部落格,請務必保留此出處http://jingshanls.blog.51cto.com/3357095/1825604

[李景山php]每天laravel-20160911|FileSystem-2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.