Permalink
Browse files

Merge pull request #95 from Kunstmaan/fix/getmediafromurl

follow redirects...
  • Loading branch information...
2 parents 39724d3 + 82eca3c commit 7e6d6687563cef212827702ab51005eeb172ba39 @krispypen krispypen committed Mar 21, 2013
Showing with 9 additions and 6 deletions.
  1. +9 −6 Helper/File/FileHelper.php
View
@@ -88,21 +88,24 @@ public function getMedia()
*/
public function getMediaFromUrl($mediaurl)
{
- $ch = curl_init($mediaurl);
- $url = parse_url($mediaurl);
- $info = pathinfo($url['path']);
- $filename = $info['filename'] . "." . $info['extension'];
- $path = rtrim(sys_get_temp_dir(), '/') . '/' . $filename;
-
+ $path = tempnam(sys_get_temp_dir(), 'kuma_');
$saveFile = fopen($path, 'w');
$this->path = $path;
+ $ch = curl_init($mediaurl);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILE, $saveFile);
curl_exec($ch);
+ $effectiveUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
+
fclose($saveFile);
chmod($path, 0777);
+ $url = parse_url($effectiveUrl);
+ $info = pathinfo($url['path']);
+ $filename = $info['filename'] . "." . $info['extension'];
+
$upload = new UploadedFile($path, $filename);
$this->getMedia()->setContent($upload);

0 comments on commit 7e6d668

Please sign in to comment.