public static file_system_to_url ( string $fs ) | ||
$fs | string |
/** * @internal * @param string $file_path */ protected function init_with_file_path($file_path) { $url = URLHelper::file_system_to_url($file_path); $this->abs_url = $url; $this->file_loc = $file_path; $this->file = $file_path; }
/** * downloads an external image to the server and stores it on the server * * @param string $file the URL to the original file * @return string the URL to the downloaded file */ public static function sideload_image($file) { $loc = self::get_sideloaded_file_loc($file); if (file_exists($loc)) { return URLHelper::file_system_to_url($loc); } // Download file to temp location if (!function_exists('download_url')) { require_once ABSPATH . '/wp-admin/includes/file.php'; } $tmp = download_url($file); preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $file, $matches); $file_array = array(); $file_array['name'] = basename($matches[0]); $file_array['tmp_name'] = $tmp; // If error storing temporarily, unlink if (is_wp_error($tmp)) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; } // do the validation and storage stuff $locinfo = pathinfo($loc); $file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name'])); return $file['url']; }