1--TEST--
2CURL file uploading
3--SKIPIF--
4<?php include 'skipif.inc'; ?>
5--FILE--
6<?php
7
8function testcurl($ch, $name, $mime = '', $postname = '')
9{
10	if(!empty($postname)) {
11		$file = new CurlFile($name, $mime, $postname);
12	} else if(!empty($mime)) {
13		$file = new CurlFile($name, $mime);
14	} else {
15		$file = new CurlFile($name);
16	}
17	curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
18	var_dump(curl_exec($ch));
19}
20
21include 'server.inc';
22$host = curl_cli_server_start();
23$ch = curl_init();
24curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=file");
25curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
26
27testcurl($ch, __DIR__ . '/curl_testdata1.txt');
28testcurl($ch, __DIR__ . '/curl_testdata1.txt', 'text/plain');
29testcurl($ch, __DIR__ . '/curl_testdata1.txt', '', 'foo.txt');
30testcurl($ch, __DIR__ . '/curl_testdata1.txt', 'text/plain', 'foo.txt');
31
32$file = new CurlFile(__DIR__ . '/curl_testdata1.txt');
33$file->setMimeType('text/plain');
34var_dump($file->getMimeType());
35var_dump($file->getFilename());
36curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
37var_dump(curl_exec($ch));
38
39$file = curl_file_create(__DIR__ . '/curl_testdata1.txt');
40$file->setPostFilename('foo.txt');
41var_dump($file->getPostFilename());
42curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
43var_dump(curl_exec($ch));
44
45curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 0);
46$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
47curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
48var_dump(curl_exec($ch));
49
50curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
51$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
52curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
53var_dump(curl_exec($ch));
54
55curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=post");
56$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
57curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
58var_dump(curl_exec($ch));
59
60curl_close($ch);
61?>
62--EXPECTF--
63string(%d) "curl_testdata1.txt|application/octet-stream|6"
64string(%d) "curl_testdata1.txt|text/plain|6"
65string(%d) "foo.txt|application/octet-stream|6"
66string(%d) "foo.txt|text/plain|6"
67string(%d) "text/plain"
68string(%d) "%s/curl_testdata1.txt"
69string(%d) "curl_testdata1.txt|text/plain|6"
70string(%d) "foo.txt"
71string(%d) "foo.txt|application/octet-stream|6"
72
73Warning: curl_setopt(): Disabling safe uploads is no longer supported in %s on line %d
74string(0) ""
75string(0) ""
76string(%d) "array(1) {
77  ["file"]=>
78  string(%d) "@%s/curl_testdata1.txt"
79}
80"
81