1--TEST--
2cURL option CURLOPT_READFUNCTION
3--CREDITS--
4WHITE new media architects - Jeroen Vermeulen
5#testfest Utrecht 2009
6--SKIPIF--
7<?php
8if (!extension_loaded("curl")) print "skip cURL extension not loaded";
9?>
10--FILE--
11<?php
12function 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  = __DIR__.DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION';
23$sReadFile  = $sFileBase.'_in.tmp';
24$sWriteFile = $sFileBase.'_out.tmp';
25$sWriteUrl  = 'file://'.$sWriteFile;
26
27file_put_contents($sReadFile,'contents of tempfile');
28$hReadHandle = fopen($sReadFile, 'r');
29
30$oCurl = curl_init();
31curl_setopt($oCurl, CURLOPT_URL,          $sWriteUrl);
32curl_setopt($oCurl, CURLOPT_UPLOAD,       1);
33curl_setopt($oCurl, CURLOPT_READFUNCTION, "custom_readfunction" );
34curl_setopt($oCurl, CURLOPT_INFILE,       $hReadHandle );
35curl_exec($oCurl);
36curl_close($oCurl);
37
38fclose ($hReadHandle);
39
40$sOutput = file_get_contents($sWriteFile);
41var_dump($sOutput);
42?>
43--CLEAN--
44<?php
45$sFileBase  = __DIR__.DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION';
46$sReadFile  = $sFileBase.'_in.tmp';
47$sWriteFile = $sFileBase.'_out.tmp';
48unlink($sReadFile);
49unlink($sWriteFile);
50?>
51--EXPECT--
52string(27) "custom:contents of tempfile"
53