Welcome Guest, Not a member yet? Register   Sign In
Read file to another server
#1

HI , i want read file from another server , the file are xls and  i want read with phpspreadsheet ,  i try to use curl :

Code:
        $client = \Config\Services::curlrequest([
            'baseURI' => 'https://myserver/',
        ]);

        // GET file
        $client->get('480060_08_06_2022.xls');

        $code  = $this->response->getStatusCode(); 
        $reason = $this->response->getReason(); 

but i have always $code equals to 200 and $reason equal to ok i f file doesn't exist too.

How can i check if file exist and read or download ?
Reply
#2

See https://codeigniter4.github.io/CodeIgnit...-responses
Reply
#3

(This post was last modified: 03-26-2024, 02:49 AM by pippuccio76.)

(03-25-2024, 06:35 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...-responses

the documentation doesn't explain how i can get the file ( to read or download) ,there is an example ?
i try to :

Code:
        $client = \Config\Services::curlrequest([
            'baseURI' => 'https://myserver/',
        ]);

        // GET file
        $client->request('GET','480060_08_06_2026.xls');

        $code  = $this->response->getStatusCode();
        $reason = $this->response->getReason();


        echo "<pre>";
        print_r($client->getBody());


But i return a 404

Edit :

i miss a x (xslx) now i haven't error , but how can i read the file ? print_r($client->getBody()) return a blank page
Reply
#4

Why cannot i  use 
Code:
$file = new \CodeIgniter\Files\File($url);
?
Reply
#5

(This post was last modified: 03-26-2024, 05:09 PM by kenjis.)

I recommend you read the user guide, because it tells everything you need in most cases.
https://codeigniter4.github.io/CodeIgnit...-responses

PHP Code:
        $client = \Config\Services::curlrequest();

        $url      'https://www.cmu.edu/blackboard/files/evaluate/tests-example.xls';
        $response $client->request('GET'$url);

        $content $response->getBody();

        file_put_contents(WRITEPATH 'sample.xls'$content); 
Reply
#6

(This post was last modified: 03-27-2024, 12:26 AM by pippuccio76.)

(03-26-2024, 05:07 PM)kenjis Wrote: I recommend you read the user guide, because it tells everything you need in most cases.
https://codeigniter4.github.io/CodeIgnit...-responses

PHP Code:
        $client = \Config\Services::curlrequest();

        $url      'https://www.cmu.edu/blackboard/files/evaluate/tests-example.xls';
        $response $client->request('GET'$url);

        $content $response->getBody();

        file_put_contents(WRITEPATH 'sample.xls'$content); 


sorry but 

Code:
file_put_contents
it is not written in this page, I love codeigniter , but i think documentation it needs to be much improved , we need examples like
 Build your first application part...
Reply
#7

file_put_contents() is a basic PHP function. It is not CodeIgniter's function.
CodeIgniter is build on PHP, so you can use PHP functions,
and you should know PHP.

Also, you can improve the user guide. Because CodeIgniter is made by contributions.
https://codeigniter4.github.io/CodeIgnit...quest.html
You can see "Edit this page" in right of the top.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB