#32549 closed defect (bug) (fixed)
wp_remote_get does not stream to temp file
| Reported by: | andddd | Owned by: | dd32 |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.3 |
| Component: | HTTP API | Version: | 4.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Source:
$filename = wp_unique_filename( get_temp_dir(), basename( $zip_url ) ); var_dump(get_temp_dir()); var_dump($zip_url); var_dump($filename); $response = wp_remote_get( $zip_url, array( 'timeout' => 15, 'stream' => true, 'filename' => $filename ) );
Output:
string(49) "/var/folders/4p/s0vgsy5s19g63q9t0zd56hkw0000gn/T/" string(77) "https://bucket.s3-eu-west-1.amazonaws.com/folder/file.zip" string(8) "file.zip"
Seems like wp_unique_filename cannot combine filename with temp path. No error returned after download. wp_remote_get crafts download path the same way so it's broken too if I omit filename option.
Change History (5)
#2
@
11 years ago
- Milestone Awaiting Review
- Resolution → invalid
- Status new → closed
The stream parameter expects a filename path to be specified, ie. /var/folders/4p/s0vgsy5s19g63q9t0zd56hkw0000gn/T/file.zip, not file.zip. If you pass a relative path into that, it's saved within the current working directory (in my testing, it went into wp-admin/ as I triggered it through wp-admin/admin-post.php).
wp_unique_filename() only returns a file name, it does not return a path, it's designed to find a unique filename within a folder.
It looks like you want to be using $filename = wp_tempnam( $zip_url ); instead of wp_unique_filename().
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The code in WP_Http::request() does need to be fixed.