SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Curl: how to use variable outside of function

    Hi

    I would like to use the variable $httpcode outside of this curl function

    The $httpcode variable is $httpcode = curl_getinfo($ch ,CURLINFO_HTTP_CODE);

    I am calling the function like this get_file1("http://example.com/myfile.gz, "myfile.gz");

    I am wondering how can i use the $httpcode variable after i have called the function?


    PHP Code:
    function get_file1($file$local_path$newfilename)
    {
        
    $err_msg '';
        echo 
    "<br>Attempting message download for $file<br>";
        
    $out fopen($newfilename'wb');
        if (
    $out == FALSE){
          print 
    "File not opened<br>";
          exit;
        }
       
        
    $ch curl_init();
               
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
        
    curl_setopt($chCURLOPT_FILE$out);
        
    curl_setopt($chCURLOPT_HEADER1);
        
    curl_setopt($chCURLOPT_URL$file);
                   
        
    curl_exec($ch);
        echo 
    "<br>Error is : ".curl_error $ch);
       
    $httpcode  curl_getinfo($ch ,CURLINFO_HTTP_CODE);  

        
    curl_close($ch);
        
    //fclose($handle);

    }//end function 
    Cheers

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code that calls the function and what i want to do with it afterwards

    PHP Code:
    get_file1("http://example.com/myfile.gz"''"myfile.gz");
                                                                                                                                                  
    if (
    $httpcode !== '200' )
    {
    rename("myfile.gz""ddd/error_".$d.".gz");

    //unlink('myfile.gz');

    }else {


    //Uncompress zip
    uncompress('myfile.gz','td_'.$d.'.csv');
                                            
    //Delete zip
    unlink('myfile.gz');

    cheers

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no problem i fixed this

    cheers

  4. #4
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you tell us how?
    my mobile portal
    ghiris.ro

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure,

    I called the function and then used the variable afterwards no problem

    It was the script that was causing the problem.

    The variable always appeared/showed. I just got it wrong myself

    thanks for all the helps from this board


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •