title: customize curl function to support download and info header in php
body: <p>hi there I googled hours to build my own custom curl function:</p>
  
  <p>Inputs are every thing ( URL of files,images,webpage etc...)</p>
  
  <p><strong>I have severall scenarios:</strong></p>
  
  <p><strong>scenario1</strong></p>
  
  <pre><code>$url = 'an broken link or file';
  $type =  null; //not important
  callCurl($url,$type,10,2); 
  </code></pre>
  
  <p>I except the function return false because of  <code>if($curl = curl_init($url))</code> But not works.(I test it with a broken file url)</p>
  
  <p><strong>scenario2</strong></p>
  
  <pre><code>$url = 'an active url file';
  $type =  'info'
  callCurl($url,$type,10,2); 
  </code></pre>
  
  <p>I except return just size of file but it first download file then give me size of it!</p>
  
  <p><strong>scenario3</strong></p>
  
  <pre><code>$url = 'an active url webpage';
  $type =  'content'
  callCurl($url,$type,10,2);
  </code></pre>
  
  <p>I except return  downloaded webpage it works. no problem!</p>
  
  <p><strong>scenario4</strong></p>
  
  <pre><code>$url = 'an active url of file or images';
  $type =  'content'
  callCurl($url,$type,10,2);
  </code></pre>
  
  <p>how can I download file or images? is it same of scenario3?</p>
  
  <p><strong>This is the function:</strong></p>
  
  <pre><code>//$type: info | content 
  // info: for example size of file or webpages without downloading 
  // content: dpwnloaded content (file/webpage/image/etc...) 
  function callCurl($url,$type,$timeout,$ctimeout)
  {
      if($curl = curl_init($url))
      {
          curl_setopt( $curl, CURLOPT_NOBODY, true );
          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
          curl_setopt($curl, CURLOPT_HEADER, true);
          curl_setopt($curl, CURLOPT_URL, $url);
          curl_setopt($curl, CURLOPT_REFERER, $url);
          curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
          curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );//
          curl_setopt($curl, CURLOPT_CONNECTTIMEOUT ,$ctimeout); 
          curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); //timeout in seconds
          curl_setopt($curl, CURLOPT_SSLVERSION,3);    
          $str = curl_exec($curl);
          if(curl_errno($curl))
          {
              echo curl_error($curl);
              curl_close($curl);
              return false;
          }
          else
          {
              if($type == 'info')
              {
                  $info['mimeType'] = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
                  $info['size'] = curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
                  $info['path'] = parse_url($url, PHP_URL_PATH);
                  $info['filename'] = substr($info['path'], strrpos($info['path'], '/') + 1);
                  curl_close($curl);
                  return $info;
              }
              elseif($type == 'content')
              {
                  return $str;
              }
  
          }
      }
      echo "This URL IS NOT ACTIVE IT IS NOT 200";
      return false;
  }
  </code></pre>
  
  <p>how can I change it to support those senarios?</p>