Welcome Guest, Not a member yet? Register   Sign In
How to view an existing document?
#1

(This post was last modified: 03-11-2020, 09:10 AM by christaliise.)

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?
Reply
#2

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 did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#4

(This post was last modified: 03-11-2020, 09:05 AM by christaliise.)

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB