Welcome Guest, Not a member yet? Register   Sign In
reading lines from file
#1

[eluser]rajneeshgobin[/eluser]
i have these code

view of the form
Code:
<?php echo form_open_multipart('uploadctrl/processID');?>


ect ect

               <td>
                  &lt;input type="file" name="orderspec_file" value="Specify file here" size="50" maxlength="80" disabled="disabled" id="orderspec_file"&gt;&lt;span id="orderspec_fileErr" class="error"></span>
                  <br>

               </td>

controller
Code:
$this->load->library('upload', $config);

  
if ( ! $this->upload->do_upload('orderspec_file'))
  {
   $error = array('error' => $this->upload->display_errors());
  }
  else
  {
   $this->session->set_flashdata('upload_data', $this->upload->data());

  }
  
  
         $this->load->view("common/shome", $data);

in shome i wish to display the content of the file

in the file i have a few lines like student_name surname

file.txt
Code:
hello world
foo bar
super man

ect

how can i list these data in the display page shome?
#2

[eluser]RobertSF[/eluser]
I have not tried it myself, but I found this in the CodeIgniter 2.1.2 User Guide.

$this->upload->data() returns an array, but the array does not contain the uploaded file. Instead, it contains information about the uploaded file. This is the information it contains.

Code:
Array
(
    [file_name] => mypic.jpg
    [file_type] => image/jpeg
    [file_path] => /path/to/your/upload/
    [full_path] => /path/to/your/upload/jpg.jpg
    [raw_name] => mypic
    [orig_name] => mypic.jpg
    [client_name] => mypic.jpg
    [file_ext] => .jpg
    [file_size] => 22.2
    [is_image] => 1
    [image_width] => 800
    [image_height] => 600
    [image_type] => jpeg
    [image_size_str] => width="800" height="200"
);

So before you load the view, you must use the above information to read the file.

You can use something like this.
Code:
$uploaded_file_info = $this->upload->data();
$uploaded_file_contents = get_file_contents($uploaded_file_info['full_path']);
$data = array('uploaded_file' => $uploaded_file_contents);
// and now you're ready for the view
$this->load->view('common/shome', $data);

Here's information on the PHP function get_file_contents.
http://php.net/manual/en/function.file-get-contents.php




Theme © iAndrew 2016 - Forum software by © MyBB