Hi all,

I'm sure there is a simple solution to this but having trying to
Google for the answer I still stuck.

The application that I am developing (my first CakePHP project!) has a
form has a hidden field that contains the URL of a feed. The feed
itself can be in any format (XML, txt, csv, etc). Once a user clicks
on the "Check Status" button the application is supposed to take the
URL and check to see if the URL exist. I've manage to get the codes
working so that it can detect xml and txt files without error. However
if the URL points to a CSV file, the browser (Firefox, Chrome) prompts
me to download the file. I've tried using both HTTPSocket and CURL to
grab the file and both gives the same results.

Here the code:

        function checkstatus(){
                $this->layout = 'ajax';
                $this->autoLayout = false;
               $this->autoRender=false;

                Configure::write('debug', 0);

                $response = array('success' => false);

               if($this->RequestHandler->isAjax()) {
                        //App::import('Core', 'HttpSocket');
                        //$HttpSocket = new HttpSocket();

                        //$request = array('uri' => 
$this->params['form']['value']);
                        //$results = $HttpSocket->request($request);
                        //$feed = new File($this->params['form']['value']);
                        //$ext = $feed->ext();

                        //$data = $feed->read();
                        //$feed->close();

                        $curl_feed = curl_init();
                        curl_setopt($curl_feed, CURLOPT_URL, 
$this->params['form']
['value']);
                        curl_setopt($curl_feed, CURLOPT_POST, true);
                        curl_setopt($curl_feed, CURLOPT_RETURNTRANSFER, true);
                        $curl_result = curl_exec($curl_feed);
                        curl_close($curl_feed);

                        if($curl_result){
                                $response['success'] = 'ok';
                        }else{
                                $response['success'] = 'xml';
                        }
                }

                $this->header('Content-Type: application/json');
                echo json_encode($response);
                return;
        }

What am I doing wrong or is there a better way I can do this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to