Annotation of embedaddon/php/ext/curl/tests/curl_setopt_CURLOPT_READFUNCTION.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: cURL option CURLOPT_READFUNCTION
        !             3: --CREDITS--
        !             4: WHITE new media architects - Jeroen Vermeulen
        !             5: #testfest Utrecht 2009
        !             6: --SKIPIF--
        !             7: <?php 
        !             8: if (!extension_loaded("curl")) print "skip cURL extension not loaded"; 
        !             9: ?>
        !            10: --FILE--
        !            11: <?php    
        !            12: function custom_readfunction($oCurl, $hReadHandle, $iMaxOut) 
        !            13: {
        !            14:   $sData = fread($hReadHandle,$iMaxOut-10); # -10 to have space to add "custom:"
        !            15:   if (!empty($sData))
        !            16:   { 
        !            17:     $sData = "custom:".$sData;
        !            18:   }
        !            19:   return $sData;
        !            20: }
        !            21: 
        !            22: $sFileBase  = dirname(__FILE__).DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION';
        !            23: $sReadFile  = $sFileBase.'_in.tmp';
        !            24: $sWriteFile = $sFileBase.'_out.tmp';
        !            25: $sWriteUrl  = 'file://'.$sWriteFile;
        !            26: 
        !            27: file_put_contents($sReadFile,'contents of tempfile');
        !            28: $hReadHandle = fopen($sReadFile, 'r');
        !            29: 
        !            30: $oCurl = curl_init();
        !            31: curl_setopt($oCurl, CURLOPT_URL,          $sWriteUrl);
        !            32: curl_setopt($oCurl, CURLOPT_UPLOAD,       1);
        !            33: curl_setopt($oCurl, CURLOPT_READFUNCTION, "custom_readfunction" );
        !            34: curl_setopt($oCurl, CURLOPT_INFILE,       $hReadHandle );
        !            35: curl_exec($oCurl);
        !            36: curl_close($oCurl);
        !            37: 
        !            38: fclose ($hReadHandle); 
        !            39: 
        !            40: $sOutput = file_get_contents($sWriteFile); 
        !            41: var_dump($sOutput);
        !            42: ?>
        !            43: ===DONE===
        !            44: --CLEAN--
        !            45: <?php
        !            46: $sFileBase  = dirname(__FILE__).DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION';
        !            47: $sReadFile  = $sFileBase.'_in.tmp';
        !            48: $sWriteFile = $sFileBase.'_out.tmp';
        !            49: unlink($sReadFile);
        !            50: unlink($sWriteFile);
        !            51: ?>
        !            52: --EXPECT--
        !            53: string(27) "custom:contents of tempfile"
        !            54: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>