Skip to content

Instantly share code, notes, and snippets.

@kyle-jennings
kyle-jennings / upload.php
Created January 11, 2019 16:26
Programmatically upload file to WordPress
// downloads a file from a URL and saves it to the /tmp folder in the OS
$tmp_file = download_url( $url );
// the file info
$file = array(
'name' => $filename_with_extension,
'type' => 'image/png',
'tmp_name' => $tmp_file, //src file
'error' => 0,
'size' => filesize( $tmp_file ),