its bit confusing with the diffrent methods on diffrent objects, which is for creating the attachment and which creates the meta txt, or both.
I first curled a image directly into page content folder, but then had trouble creating the according filename.mp4.txt
meta file, since source
property was missing (I dont even remeber which of the “file create methods” I tried)
ANYWAYS this is my solution (copy image from instagram). with help from kirby reference and examples, maybe helpful for somebody
// $obj is return object from instagram with file url and more
$source_filename = $obj->id . '-media.mp4';
$source_path = getcwd() . '/tmp/' . $source_filename;
file_put_contents($source_path, curlFile($obj->media_url));
$file = File::create([
'filename' => $source_filename,
'parent' => $page,
'source' => $source_path,
'content' => [
'caption' => 'on my'
]
]);
function curlFile($url)
{
$process = curl_init($url);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$res = curl_exec($process);
curl_close($process);
return $res;
}