3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 220 Views |
-
[SOLVED] Create Image from file_put_contents

8 December 2012 at 1:12pm
I have a class that downloads images from an external server to my SS site. What is the best way to create an image Object for a has_one relation from this file. Off the top of my head I was going to manully create a new Image from the file name and then after write get its ID and attach it to the other DataObject. But manually craete the Image object in my file table seems redundant. I assume I should just be able to use the built in file system to handle my file write and file object creation, just not sure where to start
Thanks
-
Re: [SOLVED] Create Image from file_put_contents

8 December 2012 at 4:24pm
I was going to manully create a new Image from the file name and then after write get its ID and attach it to the other DataObject.
You're on the correct track.
But manually craete the Image object in my file table seems redundant.
No you'll need to manually create the Image object as well as the actual file and ensure that the Image object you created has the correct filename to link to the image.
file_put_contents('assets/foo.jpg', $img);
$image = new Image();
$image->Filename = 'assets/foo.jpg';
$image->Title = 'Foo';
$image->write();$obj->ImageID = $image->ID:
$obj->write();
| 220 Views | ||
|
Page:
1
|
Go to Top |


