Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
file handle how to read file of csv format
  • how to read and write csv file and once we upload the file on the server 
    can u provide  a example 
  • To read any file, you can use file_get_contents(). If you need more security, for example because the location is user input, you can use the File, which allows you to restrict access to a specific area of the disk.

    Once read the data is in a string, and you can use the Format class to convert the CSV file to an array.
  • You can do something like that for example :
      $file = Input::file('csv_file');
      if ($handle = fopen($file['tmp_name'], 'r')) {
        while($csv_line = fgetcsv($handle, 0, ';'))
        {
          // you have your csv line in $csv_line array
        }
      }

  • now ower here i also need to upload the file on server can the above function can also upload the file on the server in the given director
  • and how u save a file in particular folder not the rootdoc folder , i try to change the folder by file config file and seting the //'basedir'  => 'assets/uploads/', but it is not working i am getting error as follow

    Fuel\Core\OutsideAreaException [ Error ]: File operation not allowed:

    canu tell how to set the path


  • The File Area class will do a realpath() on the basedir passed. So it can not be a relative directory like you have defined now.

    So it should be something like

    'basedir'  => DOCROOT.'assets/uploads/',
  • thank i got it but , i am working on downloading the file i am using the following code that is
    File::download(DOCROOT.'assets/uploads/reportfile.csv', 'reportfile.csv');
    but for this i am geting the following error
    ErrorException [ Error ]: Class 'finfo' not found
    733 if ( ! $fileinfo = new \finfo(FILEINFO_MIME, \Config::get('file.magic_file', null)))
    734 {
    735 throw new \InvalidArgumentException('Can not retrieve information about this file.');
    736 }
    737
    how to solve this ??? Please provide some solution
  • Read the (PHP) docs.

    As of PHP 5.3, the fileinfo extension MUST be present by default in your PHP installation. As such, FuelPHP expects it to be there. If this is your local machine, install it (for Windows, you need to load a DLL which should be pre-installed).

    If this is a hoster, complain bitterly, and if they don't fix it, switch hosting companies. As of now, there is no plain PHP workaround.

    See http://php.net/manual/en/fileinfo.installation.php

Howdy, Stranger!

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

In this Discussion