Welcome Guest, Not a member yet? Register   Sign In
File Downloading Problem
#1

[eluser]rainfall[/eluser]
I created simple file uploading page. Its upload the files and show its information .

In upload controller
Code:
$data = array('upload_data' => $this->upload->data());
.......
.......
Its contain all the information about the file .
Example : after uploading .......

Your file was successfully uploaded!

file_name: flower.jpg
file_type: image/jpeg
..............
...............

I want to retrieve file_name from upload_data for downloading the file

Here is the download controller i used
Code:
$this->load->helper('download');
                        $data = file_get_contents(base_url()."uploads/");
                        
               //        Here is the Problem  ????
                        
                        foreach ($upload_data as $item)
                        $name=$item['file_name'];    
                        force_download($name, $data);

Download not working . Path is alright but file_name not retrieving properly .
now how can i retrieve ' file_name' from upload_data to $name ????

#2

[eluser]CroNiX[/eluser]
Have you read the docs for file_get_contents()? You're giving it a url, not a file on the local filesystem.

Where is $upload_data coming from?
#3

[eluser]CroNiX[/eluser]
Not really sure why you'd download a file that you just uploaded, but try this:
Code:
//get the uploaded file info
$upload_data = $this->$this->upload->data();

//read the file using the full path/filename provided by the uploader
$file = file_get_contents($upload_data['full_path']);

//send it to the browser using the original filename
force_download($upload_data['file_name'], $file);
#4

[eluser]rainfall[/eluser]


Error occurred


For this line

$upload_data = $this->$this->upload->data();


Fatal error: Call to a member function data() on a non-object
#5

[eluser]CroNiX[/eluser]
I made a typo..$this->$this
#6

[eluser]rainfall[/eluser]
Still error occurred

in view
Code:
<td><a href="&lt;?php echo base_url();?&gt;upload/download">Download</a></td>
Here is my download controller
Code:
public function download ()
{
          
           $this->load->helper('download');
           $upload_data = $this->upload->data();

//read the file using the full path/filename provided by the uploader
          $file = file_get_contents($upload_data['full_path']);

//send it to the browser using the original filename
            force_download($upload_data['file_name'], $file);
                      
                 }

Error :
Message: Undefined property: Upload::$upload

Filename: controllers/upload.php


All are showing for this line :


$upload_data = $this->upload->data();

Fatal error: Call to a member function data() on a non-object



//read the file using the full path/filename provided by the uploader what does it mean ???
i just upload a file and want to download it

#7

[eluser]Flemming[/eluser]
Your download function has no awareness of what's been uploaded!

You would need to pass in the path to the file in order for the download function to know what file to download.

$upload_data = $this->upload->data(); only works immediately after file upload

Hope this helps?
#8

[eluser]rainfall[/eluser]
@ Flemming
Can you help me how can i get file contents ??

Need to retrieve full_path from upload_data and put it to file_get_contents() .

How ??
#9

[eluser]CroNiX[/eluser]
You're code doesn't show you using the upload class. I thought you might have been doing it elsewhere in the code and not showing it. I really am not sure what you are trying to do here as it doesn't make sense.
#10

[eluser]rainfall[/eluser]
This is my Upload function in upload controller
Code:
function do_upload()
{
  $config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx';
  $config['max_size'] = '5000';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';

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

  if ( ! $this->upload->do_upload())
  {

                    $this->showFile();
  }
  else
  
                    {
   $data = array('upload_data' => $this->upload->data());

   //$this->load->view('upload_success', $data);
                        
                         $data['page_title'] = "Upload Status";
                         $data['content_title'] = "Upload Status";
                         $data['main_content'] = $this->load->view('upload_success', $data, TRUE);
                         $this->load->view('main_design_formate',$data);
                         $this->addFile();
                        
                        
     }
when i click this link it download through download function place in upload controller
Code:
<td><a href="&lt;?php echo base_url();?&gt;upload/download">Download</a></td>

Here is download function
Code:
public function download ()
{
        
           $this->load->helper('download');
        
           $upload_data = array('upload_data' => $this->upload->data());
//read the file using the full path/filename provided by the uploader
$file = file_get_contents($upload_data['full_path']);

//send it to the browser using the original filename
force_download($upload_data['file_name'], $file);
          
                      
                 }


I think its clear now

need to get full_path and put it in file_get_contents() ??




Theme © iAndrew 2016 - Forum software by © MyBB