Downloading Files ( download_url() WP function) not working on local DevKinsta

I am programmatically creating posts and use the Wordpress download_url() function to grab an image and put it in the media library. I spent a couple of hours trying to figure out why it wasnt working and then decided to push my work to the Kinsta staging site. Well there it worked perfectly.

What is different with DevKinsta in that it cant download files from URLs?

Hello @rreyes Rex! :wave:

First of all, I’m not a programmer/developer, and I only tested the following PHP script to test the download_url() WP function (which I found on the internet and just modified it a bit) :smiley:

So, I created the following simple PHP script on my local DevKinsta site (named it as dlurl.php - located inside my ~/DevKinsta/public/agus-site/ folder):


include( 'wp-load.php' );

// If the function it's not available, require it.
if ( ! function_exists( 'download_url' ) ) {
	require_once ABSPATH . '/wp-admin/includes/file.php';

// Now you can use it!
$file_url = '';
$tmp_file = download_url( $file_url );

// Sets file final destination.
$filepath = ABSPATH . '/wp-content/uploads/downloaded-file-test.jpg';

// Copies the file to the final destination and deletes temporary file.
copy( $tmp_file, $filepath );
@unlink( $tmp_file );

The above code would download the image URL from the source:

to my local site folder as:

Previously before I opened that PHP file (dlurl.php) locally on my browser, my ~/DevKinsta/public/agus-site/wp-content/uploads folder was showing this:

~/DevKinsta/public/agus-site/wp-content/uploads$ ll
total 12
drwxrwxrwx 3 agus agus 4096 Dec  8 08:15 ./
drwxrwxrwx 6 agus agus 4096 Dec  6 09:36 ../
drwxrwxrwx 8 agus agus 4096 Dec  5 06:50 2022/

And after I accessed that dlurl.php on my browser (e.g: https://agus-site.local/dlurl.php ), I could see the image file was downloaded properly into that “wp-content/uploads” sub-folder:

~/DevKinsta/public/agus-site/wp-content/uploads$ ll
total 40
drwxrwxrwx 3 agus agus  4096 Dec  8 08:22 ./
drwxrwxrwx 6 agus agus  4096 Dec  6 09:36 ../
drwxrwxrwx 8 agus agus  4096 Dec  5 06:50 2022/
-rw-r--r-- 1 agus agus 27661 Dec  8 08:22 downloaded-file-test.jpg

and I could also then access that downloaded .jpg file in question from my local site as expected.

You may want to give it a try with the sample PHP script/code above and see if it’s working fine as expected.
If it’s still not working, maybe you could please share the exact source URL to grab an image from?

Still unsure though, but just guessing for now, in case there’s a possibility if the external host/URL can’t be resolved from your local DevKinsta FPM container - similar to this issue before.
You may want to perform these as well to verify:

  1. run this command line: docker exec -it devkinsta_fpm bash (to connect to bash on the local FPM docker container)

  2. then inside that FPM container, please try to run something like thie:
    curl -I https://the-external-url.tld/of-the-image-file.jpg

  3. If it returns with something like “curl: (6) Could not resolve host: the-external-url.tld” , then most likely it’s an issue with your local DNS server resolver in that FPM container.
    And if that’s the case, you can run this command there:
    dns_server update -d the-external-url.tld

  4. Then see if you can run cURL command again of that external URL (as shown in step 2) above. If it resolves, then please try your PHP script/code again and see if it can download the image file in question from that external host URL.

Hopefully it will help you to solve the issue with the download_url() WP function (as that seems to be working fine as per my test on my local DevKinsta as mentioned above).


Thanks for the detailed repsonse. I still cannot get it working tho. I tried ssh’ing to the container. While the curl command did work with the wikimedia image, it is not working with my image ( ) . The error i get is curl: (6) Could not resolve host:

Like i said this all works fine on my staging server at Kinsta so for now i am just working there. I would like for my local enviroment to work the same tho.

Hey @rreyes , just to clarify, does the issue persist even after following the steps listed here or by following the step number 3 shared by Agus?



Hello Rex @rreyes ,

I couldn’t replicate this inside the docker FPM container on my Linux machine, but was able to replicate that cURL issue inside the docker FPM container on my Windows machine (which seems to be the DNS resolver issue in there).

This what I got when I tested on my Windows machine:

C:\Users\iagus>docker exec -it devkinsta_fpm bash
root@b2953a82ac4c:/www/kinsta# curl -I
curl: (6) Could not resolve host:

I then tried to add that that external hostname with the following (as I mentioned in my previous reply - step 3 above):

dns_server update -d

but still that didn’t resolve that external hostname via cURL:

root@b2953a82ac4c:/www/kinsta# dns_server update -d
root@b2953a82ac4c:/www/kinsta# curl -I
curl: (6) Could not resolve host:

Then I checked further on my Linux machine (same network/ISP as my Windows machine), and I could see the hostname: resolves to multiple A records/IP addresses, and the results might change/vary from different locations (and from your location as well):

$ host is an alias for has address has address has address has address has address has address has address has address

You can also check the same with this 3rd party tool:

So I altered the command a bit to be something like this on my Windows / local docker FPM container (I added the first 3 IPs showed on my Linux terminal above):

dns_server add -d -A the.ip.address.listed.above

root@b2953a82ac4c:/www/kinsta# dns_server add -d -A
root@b2953a82ac4c:/www/kinsta# dns_server add -d -A
root@b2953a82ac4c:/www/kinsta# dns_server add -d -A

After that, I was able to perform the cURL command line to access that image URL (external host) inside the docker FPM container on my Windows machine:

root@b2953a82ac4c:/www/kinsta# curl -I
HTTP/1.1 200 OK
x-amz-id-2: 4romAENZjlpN+NUibPf1pLY4NnD79axdqmxLzUPHNJRc287PS0HQ5Ni8CTaRVMyVmmhcUUSOSfI=
x-amz-request-id: ZR4CCCC3XES0NFAG
Date: Fri, 09 Dec 2022 03:49:17 GMT
Last-Modified: Thu, 27 Oct 2022 16:41:03 GMT
ETag: "a0760718792e9085e132d07a57760296"
Accept-Ranges: bytes
Content-Type: image/jpeg
Server: AmazonS3
Content-Length: 51453

I suspect you might be using Windows as well? if that so, please try the steps I mentioned above and see if it will help to resolve that external host name on your local docker FPM container . Once the cURL can resolve that URL/hostname, then you should be able to access the same URL from your PHP scripts.