CodeIgniter Forums

Full Version: How to view an existing document?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have existing documents which are uploaded into the root directory, the same directory as "application", that is uploaded at the time of registration.

I want to be able to view those documents via a Controller & view, which I have already established.

The Controller coding I have is:-

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Docs extends CI_Controller
{

public function 
index()
    {
    
$this->load->view('member/chris/docs');
$doc fopen("C:xampp/htdocs/member/$user/photo/chris.jpg""a"); //Not sure if this is the right approach
    
}


I guess the name of the uploaded documents would need to be standardized (chris.jpg to photo.jpg), but I'll query that once I get the document viewed.

I have in the view page coding that echos the username which works OK.

But I dont know the code to view documents.

Can anybody help?

Update

I now need to learn how to standardize the document name when uploaded for example C:xampp/htdocs/member/$user/photo/chris.jpg to be automatically changed to C:xampp/htdocs/member/$user/photo/photo.jpg

Anybody with any suggestions?
For one the view needs to be the last thing that you load.

You want to do something like the below code:

PHP Code:
$data['photo'] = 'c:\xampp\user\photos\user.jpg';
$data['docs']  'c:\xampp\user\docs\userdoc.ext';

$this->load->view('view_name'$data); 

Then in your view file just echo out $photo and $docs where you want them.
What do you want to do with the file? If you just need to display it in a view, you only need a href link. No need to call fopen.
(03-10-2020, 08:03 AM)includebeer Wrote: [ -> ]What do you want to do with the file? If you just need to display it in a view, you only need a href link. No need to call fopen.

Thanks @includebeer a simple href link did the job.

(03-10-2020, 08:00 AM)InsiteFX Wrote: [ -> ]For one the view needs to be the last thing that you load.

You want to do something like the below code:

PHP Code:
$data['photo'] = 'c:\xampp\user\photos\user.jpg';
$data['docs']  'c:\xampp\user\docs\userdoc.ext';

$this->load->view('view_name'$data); 

Then in your view file just echo out $photo and $docs where you want them.

Thanks @InsiteFX Im trying to avoid using the database & I do prefer @includebeer's simpler solution. However I may need your idea somewhere else in my project.