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