Created
September 17, 2015 21:56
-
-
Save styks1987/63e6cb64b001a0e1e006 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function migrate_thumbnail($label_id, $filename) | |
{ | |
$LabelThumb = new Thumb(); | |
$file = $LabelThumb->get_local_filename($label_id); | |
$tmp_file = $this->save_to_filepicker($file, ['filename'=>$label_id.'.png']); | |
} | |
function save_to_filepicker($file, $options =[]) | |
{ | |
$postfields = ["fileUpload" => new CurlFile(realpath($file))]; | |
$options = array_merge($options, ['key'=>'XXXXXXXXXXXXXXXX']); | |
$options = http_build_query($options); | |
$url = 'https://www.filepicker.io/api/store/S3?'.$options; | |
return $this->post_filepicker($url, $postfields); | |
} | |
function post_filepicker($url, $postfields = []) | |
{ | |
$headers = ["Content-Type:multipart/form-data"]; // cURL headers for file uploading | |
$ch = curl_init(); | |
$curl = curl_init($url); | |
curl_setopt_array($curl, [ | |
CURLOPT_SAFE_UPLOAD => false, | |
CURLOPT_POST => 1, | |
CURLOPT_POSTFIELDS => $postfields, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_HTTPHEADER => $headers | |
]); | |
$result = curl_exec($curl); | |
curl_close($curl); | |
return json_decode($result, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment