Is it possible to create a file object using File::create() from an image in a remote server? I have tried passing the remote url as “source” in File::create() but I get an error message that: ‘The file could not be created’.
Creating/updating etc. of stuff is only possible with authentication, have you tried that?
// authenticate as almighty
kirby()->impersonate('kirby');
you can download the file using remote::get()
(see source)
after impersonating a user you can create file for page.
Ok, done! I was trying to download the image and create a file object in one step using File::create().
For future reference you need to first get the file with Remote::get, then save it with File::write and then create the object with File::create.
thanks a lot!
Any chance I can see what that would look on paper…
<?php
$remote_img = "https://google.com/images/kitty.jpg";
...
What do you mean?
Sorry. I was requesting an example of what this would look like when coding it out. I have a variable that holds a path to a remote image. It’s huge. I want to turn that image into a file object then use Kirby’s resize helper on it. Just looking for an example to better understand.
I know I’m late to the party, but … as @Cuboctaedro wrote:
For future reference you need to first get the file with
Remote::get
, then save it withFile::write
and then create the object withFile::create
.
Simple as that!
@S1SYPHOS, Thanks for sharin’ your insight on this.