[Li Jingshan php] every day laravel-20160911| FileSystem-2

Source: Internet
Author: User

   /**    * 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


This article is from the "Focus on PHP" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1825604

[Li Jingshan php] every day laravel-20160911| FileSystem-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.