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.php?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
45$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
46curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
47var_dump(curl_exec($ch));
48
49curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
50$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
51curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
52var_dump(curl_exec($ch));
53
54curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=post");
55$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
56curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
57var_dump(curl_exec($ch));
58
59curl_close($ch);
60?>
61--EXPECTF--
62string(%d) "curl_testdata1.txt|application/octet-stream"
63string(%d) "curl_testdata1.txt|text/plain"
64string(%d) "foo.txt|application/octet-stream"
65string(%d) "foo.txt|text/plain"
66string(%d) "text/plain"
67string(%d) "%s/curl_testdata1.txt"
68string(%d) "curl_testdata1.txt|text/plain"
69string(%d) "foo.txt"
70string(%d) "foo.txt|application/octet-stream"
71
72Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in %s on line %d
73string(%d) "curl_testdata1.txt|application/octet-stream"
74string(0) ""
75string(%d) "array(1) {
76  ["file"]=>
77  string(%d) "@%s/curl_testdata1.txt"
78}
79"
80