Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,8 @@ protected function upload_from_data( $data, $headers, $time = null ) {

$size_check = self::check_upload_size( $file_data );
if ( is_wp_error( $size_check ) ) {
@unlink( $tmpfname );

return $size_check;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/rest-api/rest-attachments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,28 @@ public function test_create_item_with_data_exceeds_multisite_max_filesize() {
$this->assertErrorResponse( 'rest_upload_file_too_big', $response, 400 );
}

/**
* @ticket 66409
* @group multisite
* @group ms-required
*/
public function test_create_item_with_data_exceeds_multisite_max_filesize_removes_temp_file() {
wp_set_current_user( self::$author_id );
update_site_option( 'fileupload_maxk', 1 );
update_site_option( 'upload_space_check_disabled', false );

$temp_files = glob( get_temp_dir() . 'canola-*.tmp' );

$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
$request->set_header( 'Content-Type', 'image/jpeg' );
$request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' );
$request->set_body( file_get_contents( self::$test_file ) );

$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_upload_file_too_big', $response, 400 );
$this->assertSame( $temp_files, glob( get_temp_dir() . 'canola-*.tmp' ), 'The temporary file should be removed when the upload is rejected.' );
}

/**
* @ticket 43751
* @group multisite
Expand Down
Loading