Have just concern about the media_sideload_image function, its does support https links image? and the wp_upload_dir() support https too?

I've tried using media_sideload_image to upload image with https links.

This is my sample code:

$url     = "https://cdnl.sanmar.com/catalog/images/29M.jpg";
$post_id = 0;
$desc    = "The WordPress Logo";

$image = media_sideload_image( $url, $post_id, $desc, 'id' );

if(is_wp_error($image)) {
    echo $image->get_error_message();
}else {
    echo $image;

It gives me an error of: cURL error 7: Failed to connect to cdnl.sanmar.com port 443: Connection timed out

How can I work make it work? Please Help.

  • media_sideload_image() does support https links (as in the codex example at the bottom of this page: developer.wordpress.org/reference/functions/… , on which your code seems to be based ;) ) Your code looks good, the issue is likely on the server level, either yours or the remote one. For troubleshooting I would try to run your code from another server and/or try with a different remote url. – Iceable Jun 28 '18 at 10:11
  • Thak you @Iceable. I guess I have problem with my server, I tried free hosting and it works. – Rojan Jun 29 '18 at 3:20
  • my url is https but it doesnot work for me – ghazaleh javaheri Jan 18 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.