diff --git a/lib/filestorage/file_system.php b/lib/filestorage/file_system.php index 3d6ff5b6056..21ebe77086e 100644 --- a/lib/filestorage/file_system.php +++ b/lib/filestorage/file_system.php @@ -362,7 +362,7 @@ abstract class file_system { public function add_to_curl_request(stored_file $file, &$curlrequest, $key) { // Note: curl_file_create does not work with remote paths. $path = $this->get_local_path_from_storedfile($file, true); - $curlrequest->_tmp_file_post_params[$key] = curl_file_create($path); + $curlrequest->_tmp_file_post_params[$key] = curl_file_create($path, null, $file->get_filename()); } /** diff --git a/lib/tests/filelib_test.php b/lib/tests/filelib_test.php index cb40c8fe7e8..b6109d98164 100644 --- a/lib/tests/filelib_test.php +++ b/lib/tests/filelib_test.php @@ -545,6 +545,29 @@ class core_filelib_testcase extends advanced_testcase { $this->assertSame('OK', $contents); } + public function test_curl_file_name() { + $this->resetAfterTest(); + $testurl = $this->getExternalTestFileUrl('/test_file_name.php'); + + $fs = get_file_storage(); + $filerecord = array( + 'contextid' => context_system::instance()->id, + 'component' => 'test', + 'filearea' => 'curl_post', + 'itemid' => 0, + 'filepath' => '/', + 'filename' => 'test.txt' + ); + $teststring = 'moodletest'; + $testfile = $fs->create_file_from_string($filerecord, $teststring); + + // Test post with file. + $data = array('testfile' => $testfile); + $curl = new curl(); + $contents = $curl->post($testurl, $data); + $this->assertSame('OK', $contents); + } + public function test_curl_protocols() { // HTTP and HTTPS requests were verified in previous requests. Now check diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 38772ea50e4..1c0781b3291 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -46,6 +46,7 @@ information provided here is intended especially for developers. update to use the ModalEvents.save and ModalEvents.cancel events instead of their yes/no counterparts. * Instead of checking the 'moodle/course:viewparticipants' and 'moodle/site:viewparticipants' capabilities use the new functions course_can_view_participants() and course_require_view_participants(). +* $stored_file->add_to_curl_request() now adds the filename to the curl request. === 3.3.1 ===