1--TEST--
2move_uploaded_file() function
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--POST_RAW--
6Content-type: multipart/form-data, boundary=AaB03x
7
8--AaB03x
9content-disposition: form-data; name="field1"
10
11Joe Blow
12--AaB03x
13content-disposition: form-data; name="file1"; filename="file1.txt"
14Content-Type: text/plain
15
16abcdef123456789xxxDDDxxxDDDxxxDDD
17--AaB03x
18content-disposition: form-data; name="file2"; filename="file2.txt"
19Content-Type: text/plain
20
21abcdef123456789
22--AaB03x--
23--FILE--
24<?php
25
26echo "Valid move\n";
27$destination1 = __FILE__ . ".tmp";
28
29var_dump(move_uploaded_file($_FILES['file1']['tmp_name'], $destination1));
30$file_contents = file_get_contents($destination1);
31$contents_matches = ($file_contents == "abcdef123456789xxxDDDxxxDDDxxxDDD");
32var_dump($contents_matches);
33unlink($destination1);
34echo "\n";
35
36echo "Original name of uploaded file\n";
37$destination2 = __FILE__ . ".tmp2";
38var_dump(move_uploaded_file($_FILES['file1']['name'], $destination2));
39
40echo "Non-uploaded source file\n";
41$source = __FILE__;
42$destination3 = __FILE__ . ".tmp3";
43var_dump(move_uploaded_file($source, $destination3));
44
45echo "Valid move to existing file\n";
46$destination4 = __FILE__ . ".tmp4";
47$fd = fopen($destination4, "w");
48fclose($fd);
49var_dump(move_uploaded_file($_FILES['file2']['tmp_name'], $destination4));
50unlink($destination4);
51
52echo "Wrong parameters\n";
53var_dump(move_uploaded_file());
54var_dump(move_uploaded_file(1, 2, 3));
55
56
57?>
58--EXPECTF--
59Valid move
60bool(true)
61bool(true)
62
63Original name of uploaded file
64bool(false)
65Non-uploaded source file
66bool(false)
67Valid move to existing file
68bool(true)
69Wrong parameters
70
71Warning: move_uploaded_file() expects exactly 2 parameters, 0 given in %s on line %d
72NULL
73
74Warning: move_uploaded_file() expects exactly 2 parameters, 3 given in %s on line %d
75NULL
76