How can i download file in Codeingiter - codeigniter

I want to give download file option my webpage , but the file which i want to download is present on download link of another website , how can i directly download it from my webpage ,using CODEIGNITER

If you want download a file direct to your web site root folder use this code.
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/your_folder_name/add_file_name.jpg..ect", "your_file_path_want_to_download");
hope it will help you.

You can download files using download helper in codeigniter. first you need to and $this->load->helper('download'); in your constructor or method. after that use following code for download.
force_download('/path/to/photo.jpg', NULL);

You can Use download helper in Codeigniter. simple load helper in your controller where you need like this
$this->load->helper('download');
here is ex
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);

Related

Is it possible to test file download in Laravel 5.4?

With Laravel 5.4, it's now easy to test file upload: https://laravel.com/docs/5.4/http-tests#testing-file-uploads
Is there a way to test file download too? Ex: I want to check if a CSV is generated on a click on a button.
I did not found anything about this. What are the best practices about file download testing in Laravel?
you can try with this solution to check if the file was generated while the clicked button
if($request->hasfile('nameOfInput'))
{
//your code
}

autoload twilio in codeigniter

I have just downloaded twilio-php-master.zip and extracted the file to the libraries folder in codeigniter. I would like to know what files to set on $autoload['libraries'] = array() to use the REST API.
Thank you.
First extract the Twilio folder inside the twilio-php-master.zip into the same level as your applications folder in codeigniter,
Next set $config['composer_autoload'] = 'Twilio/autoload.php'; in your config.php
lastly add use Twilio\Rest\Client; in the controller where you are going to use Twilio
Hope this helps you...

Laravel 5 public folder asset management

I have a file stored in public/files/sample.pdf. When I want to download the file using Download. It says not found. What will be the correct path. Thank you.
/files/sample.pdf
You can always use
href="{{asset('files/sample.pdf')}}"
It will be easier
You should apply url function instead of paste the directory directly.
Download
If you're really looking for a download response when clicking the link, you should have the URL link to a controller method.
<a href="{{ url('route/to/method') }}">
Now in the controller method
return response()->download(public_path('files/sample.pdf'));
Laravel responses

export to pdf using codeigniter & bootstrap

i have a web project. In my project, i would like to give button to export file to pdf. i'm using bootstrap & codeigniter.
can anyone give example for export file to pdf in codeigniter ?
Found this while trying to do the same. https://davidsimpson.me/2013/05/19/using-mpdf-with-codeigniter/
In place of redirect() function used on the page, you can use the code below to force download. Note that redirect() will only open the file in some browsers like chrome.
$this->load->helper('download');
$data = file_get_contents(base_url("downloads/reports/$filename.pdf")); // Read the file's contents
$name = 'mynewfile.pdf';
force_download($name, $data);
Don't forget to add the .pdf extension to $name
I am using TCPDF to generate pdf files in codeigniter. check this out.TCPDF examples

Codeigniter redirection

Hi I created a codeigniter project but when I click on a link to one of my functions, example add user, I get redirected to the main page of my local host XAMPP installation instead of being taken to the correct application url. What can be the problem? Thanks
Have you set the base URL in the CI configuration? file projectname/application/config/config.php? This might be the problem... I guess your project isn't on the webroot, but your base URL is missing the /projectname/ part.
$config['base_url'] = 'http://example.com/projectname/';
How do you create the link (can you show us the code)? If you are not using the URLHelper take a look at urlHelper.
I am just guessing, but maybe you are missing the Controller name (you have to load the UrlHelper), e.g.:
Link to the controllers method
or (see Jordan Arsenault's comment below on the usage of the site_url call for better performance):
<?= anchor('/name_of_the_controller/method_to_invoke', 'Link to the controllers method'); ?>
I hope this helps.

Resources