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 52?> 53--EXPECT-- 54Valid move 55bool(true) 56bool(true) 57 58Original name of uploaded file 59bool(false) 60Non-uploaded source file 61bool(false) 62Valid move to existing file 63bool(true) 64