help on using curl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shotokan99

    #1

    help on using curl

    hi,
    i wanted to accomplish these task:

    1. from that webservice get a certain set of strings from the header
    2. next, generate the image.

    and these 2 steps will be done at the same time.

    to get the header value:
    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $xmyurl);
    curl_setopt($ch , CURLOPT_HEADER, 1);

    ob_start();
    curl_exec($ch);
    $s=ob_get_conte nts();

    now from the same url i want also to generate the image on the file.
    if just to create the image:

    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $xmyurl);
    curl_setopt ($ch, CURLOPT_CONNECT TIMEOUT, $timeout);
    // Getting binary data
    curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
    curl_setopt($ch , CURLOPT_BINARYT RANSFER, 1);

    $image = curl_exec($ch);
    curl_close($ch) ;

    now...how to combine both functions?

  • petersprc

    #2
    Re: help on using curl

    You could try CURLOPT_HEADERF UNCTION, example here:



    On Jul 2, 5:08 am, shotokan99 <soft_devj...@y ahoo.comwrote:
    hi,
    i wanted to accomplish these task:
    >
    1. from that webservice get a certain set of strings from the header
    2. next, generate the image.
    >
    and these 2 steps will be done at the same time.
    >
    to get the header value:
    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $xmyurl);
    curl_setopt($ch , CURLOPT_HEADER, 1);
    >
    ob_start();
    curl_exec($ch);
    $s=ob_get_conte nts();
    >
    now from the same url i want also to generate the image on the file.
    if just to create the image:
    >
    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $xmyurl);
    curl_setopt ($ch, CURLOPT_CONNECT TIMEOUT, $timeout);
    // Getting binary data
    curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
    curl_setopt($ch , CURLOPT_BINARYT RANSFER, 1);
    >
    $image = curl_exec($ch);
    curl_close($ch) ;
    >
    now...how to combine both functions?

    Comment

    • shotokan99

      #3
      Re: help on using curl

      how to write a callback function that will simply get a custom field
      from the header? if i run this code:
      $ch = curl_init();
      $timeout = 0;
      curl_setopt ($ch, CURLOPT_URL, $xmyurl);
      curl_setopt($ch , CURLOPT_HEADER, 1);

      ob_start();
      curl_exec($ch);
      $s=ob_get_conte nts();
      echo var_dump($s);

      i get this result:
      string(712) "HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-
      Disposition: attachment; filename=5abe32 5176661.png ...."

      now there are part of the string that i wanted to take..perhaps i can
      use strpos,preg_mat ch...etc.




      Comment

      Working...