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===DONE===
44--CLEAN--
45<?php
46$sFileBase  = __DIR__.DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION';
47$sReadFile  = $sFileBase.'_in.tmp';
48$sWriteFile = $sFileBase.'_out.tmp';
49unlink($sReadFile);
50unlink($sWriteFile);
51?>
52--EXPECT--
53string(27) "custom:contents of tempfile"
54===DONE===
55