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

[eluser]CroNiX[/eluser]
Your download functionality is NOT a part of the same request to the server as when you upload, so nothing in the upload class would be available.

You do the upload and then that's done.
You then click a link to download.

Those are 2 totally separate calls to the server and one has no knowledge of the other.
#12

[eluser]rainfall[/eluser]
Is there any way to get do_upload from upload controller and use it in download controller ??
#13

[eluser]CroNiX[/eluser]
Not directly, but you might be able to store it in session. It really depends on how this flow works.

Where is this coming from?
Code:
<td><a href="&lt;?php echo base_url();?&gt;upload/download">Download</a></td>

Is it a page that you can get to anytime? Or only right after you upload the file? Is it a part of the 'main_design_formate' view file?
#14

[eluser]rainfall[/eluser]
Hmm
after uploading its show the uploaded list below upload form
for each file their is a download link
#15

[eluser]CroNiX[/eluser]
I don't understand why you are doing this. Why upload a file and then download it? The person who uploaded it already has it.
#16

[eluser]rainfall[/eluser]
Suppose i am a admin and i upload a Leave.pdf file . Now an Employee can download this file from file list .
Thats why im trying to do this .. File list visible for employee. ..
#17

[eluser]CroNiX[/eluser]
Then it would be best to store the uploaded filename in the db, and then create links for them for people who have access.
#18

[eluser]rainfall[/eluser]
Insert file name manually or retrieve from upload_data ???
#19

[eluser]CroNiX[/eluser]
When you upload a file using the upload helper, store it on the server and also get the filename and put in the database.
Code:
if ($this->upload->do_upload())
{ //upload was successful, grab the filename and insert in db
  $file_info = $this->upload->data();
  $this->db->insert('table', array('filename' => $file_info['file_name']));
}
else
{
  //there was an upload error
}
On the page where someone can download a file, just grab the filenames from the db and create links for them.

Code:
&lt;?php foreach($files as $file): ?&gt;
<div><a href="/path/to/file/&lt;?php echo $file['filename']; ?&gt;">&lt;?php echo $file['filename']; ?&gt;</a></div>
&lt;?php endforeach; ?&gt;

There is no reason to use file_get_contents() and manually send it to the browser unless you don't want the user to know the path to the file. Clicking on the actual link to the file will do the same thing and just download the file.

The above is just a very basic sample to give you the concept.
#20

[eluser]rainfall[/eluser]
Successfully Implemented Upload and Download

Thanks a lot Smile




Theme © iAndrew 2016 - Forum software by © MyBB