1--TEST--
2CURL file uploading from string
3--EXTENSIONS--
4curl
5--FILE--
6<?php
7
8function testcurl($ch, $postname, $data, $mime = null)
9{
10	if (is_null($mime)) {
11		// for default mime value
12		$file = new CURLStringFile($data, $postname);
13	} else {
14		$file = new CURLStringFile($data, $postname, $mime);
15	}
16	curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
17	var_dump(curl_exec($ch));
18}
19
20include 'server.inc';
21$host = curl_cli_server_start();
22$ch = curl_init();
23curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=string_file");
24curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
25
26$data = "test\0test";
27var_dump(md5($data));
28testcurl($ch, 'foo.txt', $data);
29testcurl($ch, 'foo.txt', $data, 'text/plain');
30testcurl($ch, '', $data);
31testcurl($ch, 'foo.txt', '');
32testcurl($ch, "foo.txt\0broken_string", $data, "text/plain\0broken_string");
33
34// properties
35$file = new CURLStringFile($data, 'foo.txt');
36$file->mime = 'text/plain';
37var_dump($file->mime);
38var_dump($file->postname);
39var_dump(md5($file->data));
40curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
41var_dump(curl_exec($ch));
42
43// serialization / deserialization
44$old = new CURLStringFile($data, 'foo.txt', 'text/plain');
45$serialized = serialize($old);
46$new = unserialize($serialized);
47curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $new));
48var_dump(curl_exec($ch));
49
50// destroy object before send request
51$file = new CURLStringFile($data, 'foo.txt', 'text/plain');
52curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
53unset($file);
54var_dump(curl_exec($ch));
55
56// clone curl handler
57$file = new CURLStringFile($data, 'foo.txt', 'text/plain');
58curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
59$ch2 = clone $ch;
60var_dump(curl_exec($ch2));
61
62// properties are references
63
64$file = new CURLStringFile($data, 'foo.txt', 'text/plain');
65$data =& $file->data;
66$postname =& $file->postname;
67$mime =& $file->mime;
68curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
69var_dump(curl_exec($ch));
70
71?>
72--EXPECTF--
73string(%d) "62942c05ed0d1b501c4afe6dc1c4db1b"
74string(%d) "foo.txt|application/octet-stream|62942c05ed0d1b501c4afe6dc1c4db1b"
75string(%d) "foo.txt|text/plain|62942c05ed0d1b501c4afe6dc1c4db1b"
76string(%d) "error:4"
77string(%d) "foo.txt|application/octet-stream|d41d8cd98f00b204e9800998ecf8427e"
78string(%d) "foo.txt|text/plain|62942c05ed0d1b501c4afe6dc1c4db1b"
79string(%d) "text/plain"
80string(%d) "foo.txt"
81string(%d) "62942c05ed0d1b501c4afe6dc1c4db1b"
82string(%d) "foo.txt|text/plain|62942c05ed0d1b501c4afe6dc1c4db1b"
83string(%d) "foo.txt|text/plain|62942c05ed0d1b501c4afe6dc1c4db1b"
84string(%d) "foo.txt|text/plain|62942c05ed0d1b501c4afe6dc1c4db1b"
85string(%d) "foo.txt|text/plain|62942c05ed0d1b501c4afe6dc1c4db1b"
86string(%d) "foo.txt|text/plain|62942c05ed0d1b501c4afe6dc1c4db1b"
87