Welcome Guest, Not a member yet? Register   Sign In
anchor for file in WRITEPATH
#1

Hi , i move my uploaded file in  WRITEPATH.'/uploads/' . How can i set anchor to downolad file ?
I try :
Code:
<?=WRITEPATH.'uploads/'.$row->nome_originale  ?>
But have server name two time....
Reply
#2

Look in the CodeIgniter User Guide Global Funtions.

PHP Code:
$newName $file->getRandomName();
$file->move(WRITEPATH 'uploads'$newName); 
What did you Try? What did you Get? What did you Expect?

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

(This post was last modified: 09-17-2022, 01:02 AM by captain-sensible.)

from a form
Code:
$file = $this->request->getFile('userfile');

//line in form is
<input type="file" name="userfile" size="20" required/>
//then in controller

$file = $this->request->getFile('userfile');
                   $name= $file->getName();

So now we have the name of the file with its extension.

you could save that info into a database, even with a slug name if required;to retrieve later and since you know where you put it you have:

name of file
location of file

for a download link for a specfic pdf in routes i have :
Code:
$routes->get('linkPdf/(:segment)','ProducePDF::getPdf/$1');
and in a view(with an a href  link)  i display something like :

https://myweb/linkPdf/Adinkra-symbols-of-Ghana

//So using the slug : Adinkra-symbols-of-Ghana  i can query a db and get Id,  path to image etc

that should give you something to think around

so linkPdf/Adinkra-symbols-of-Ghana goes to ProducePDF::getPdf

where ProducePdf is a class and getPdf is one of its methods that does all the work.
CMS CI4     I use Arch Linux by the way 

Reply
#4

(09-17-2022, 12:58 AM)captain-sensible Wrote: from a form
Code:
  $file = $this->request->getFile('userfile');

//line in form is
<input type="file" name="userfile" size="20" required/>
//then in controller

$file = $this->request->getFile('userfile');
      $name= $file->getName();

So now we have the name of the file with its extension.

you could save that info into a database,  even with a slug name if required;to retrieve later  and since you know where you put it you have:

name of file
location of file

for a download link for a specfic pdf in routes i have :
Code:
$routes->get('linkPdf/(:segment)','ProducePDF::getPdf/$1');
and in a view(with an a href  link)  i display something like :

https://myweb/linkPdf/Adinkra-symbols-of-Ghana

//So using the slug : Adinkra-symbols-of-Ghana  i can query a db and get Id,  path to image etc

that should give you something to think around

so  linkPdf/Adinkra-symbols-of-Ghana  goes to  ProducePDF::getPdf

where ProducePdf is a class and getPdf is one of its methods that does all the work.

And to force download of a file ?
Reply
#5

a simple html download link is :
Code:
<a href="/path/image.jpg" download> text </a>
So your task is to use controller to get file details. Personally i make uploads to directory inside public , that makes it easier to get path

Then think of how to express the code in the code box in a view. try it in basic html5 ; when the text is clicked on the file downloads.
CMS CI4     I use Arch Linux by the way 

Reply




Theme © iAndrew 2016 - Forum software by © MyBB