Skip to content

Commit

Permalink
fix image upload (#1807)
Browse files Browse the repository at this point in the history
* fix image upload

* fix

* improved

* improved
  • Loading branch information
vairafiq authored Aug 18, 2024
1 parent a336902 commit 6d59caf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion includes/rest-api/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,23 @@ function directorist_rest_upload_image_from_url( $image_url ) {
);
}

$allowed_mime_types = get_allowed_mime_types();

// Add extension to the name when downloaded from extension less url
if ( strrpos( $file_array['name'], '.' ) === false ) {
$mime_type = mime_content_type( $file_array['tmp_name'] );
$_mime_types = array_flip( $allowed_mime_types );
$extensions = $_mime_types[ $mime_type ] ?? '';
$extensions = explode( '|', $extensions, 2 );
$file_array['name'] .= '.' . $extensions[0];
}

// Do the validation and storage stuff.
$file = wp_handle_sideload(
$file_array,
array(
'test_form' => false,
'mimes' => directorist_rest_allowed_image_mime_types(),
'mimes' => $allowed_mime_types,
),
current_time( 'Y/m' )
);
Expand Down

0 comments on commit 6d59caf

Please sign in to comment.