Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Unexpected result from File::read
  • I had unexpected results when using File::read to get the file size.
    It does indeed return the file size but also outputs the contents of the file to screen.
    Am I missing something? I can reproduce the behavior as follows. 1) Setup a clean install
    2) Change action_index in Controller_Welcome to:
     public function action_index()
     {
      $path     = APPPATH.'config/test.php';
      $filesize = File::read($path);
      Debug::dump($filesize);
    
      $this->response->body = View::factory('welcome/index');
     }
    
    3) Create file APPPATH/config/test.php with the following contents:
    <?php
    
    return array (
    
     'test_key1' => 'test data 1',
     'test_key2' => 'test data 2',
     'test_key3' => 'test data 3',
    );
    /* End of file temp.php */
    

    A screenshot of the results. 2Gpsk.png
  • The docs aren't entirely complete on this, when $as_string is set to false the file's contents are added to the output without going through PHP. When the $as_string param is true the contents are returned. It's 2 ways of reading the file: either by direct output or by returning it as a string, not meant for getting the filesize.
  • Thanks for clearing that up.
    Guess I'll do it the old fashioned way
    $filesize = filesize($filename);
    
    ;)
  • Paul Boco wrote on Sunday 29th of May 2011:
    Thanks for clearing that up.
    Guess I'll do it the old fashioned way
    $filesize = filesize($filename);
    
    ;)

    The File class now has some new method like get_size and get_permission on the develop branch and the soon to come RC3, just so you know.
  • @FrenkyNet, Thanks, I'll check it out. I've been trying to settle on one framework since the first of the year. Fuel is it!
    Great support, great community, great developers and a really great framework.
  • I keep getting an error when using the File class. Not sure if it's me (as usual) or Fuel.
    In a clean install of RC3 I changed action_index in Controller_Welcome to:
     public function action_index()
    {
      $area = \File::instance('my_area');
      $this->response->body = View::factory('welcome/index');
     }
    
    Then, I added file.php to app/config with the following contents:
    <?php
    
    return array(
     // inside app/config/file.php
     'areas' => array(
      'my_area' => array(
       'basedir'  => DOCROOT.'uploads',
       'use_locks'  => true,
      ),
     ),
    );
    /* End of file file.php */
    
    Lastly, I created directory public/uploads.
    Calling welcome/index reaps the following:
    Notice!
    
    ErrorException [ Notice ]: Object of class Fuel\Core\File_Area could not be converted to int
    
    COREPATH/classes/file.php @ line 49:
    
    48:{
    49: static::$areas[$name] = \File_Area::factory($config) + static::$base_area;
    50: }
    

    What am I doing wrong?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion