3066 Posts in 866 Topics by 648 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1509 Views |
-
Create Array from File Object

14 July 2010 at 6:17am
I'm trying to create a function to download all product images from a site as a zip file. I need to get the all the images paths as an array to pass to a zip file creator function. I'm halfway there. I can get get all the images needed as a DataObject but now I need to pass just the Filename column as an array. This is what I have so far:
public function DownloadAllImages(){
//$records = DataObject::get("ToyImage", "Type= 'Normal'");
$records = DB::query("SELECT * FROM ToyImage WHERE Type ='Normal'");
$returnImages = new DataObjectSet();
$filePaths = array();
if ($records) {
//return $records;
foreach($records as $record){
$imageID = $record['AttachmentID'];
$returnImages->push(new ArrayData(array(
'Name' => DataObject::get_by_id('File', $imageID)
)));
}
return $returnImages;
} else {
return false;
}
}Thanks in advance
-
Re: Create Array from File Object

15 July 2010 at 2:11am
That returns an empty array.
If I change it to $returnImages->map('ID','Name'); I get only last DataObject;
-
Re: Create Array from File Object

15 July 2010 at 3:04am
Ok, then let's keep it simple...
public function DownloadAllImages(){
$records = DataObject::get("ToyImage", "Type= 'Normal'");
$filePaths = array();if ($records) {
foreach($records as $record){
$File = DataObject::get_by_id('File', $record->AttachmentID);
$filePaths[] = $File->Filename;
}
return $filePaths;
} else {
return false;
}
} -
Re: Create Array from File Object

15 July 2010 at 4:22am
Thanks That Got it.
The simpler the better I guess
-
Re: Create Array from File Object

6 August 2010 at 12:13pm
Hey, Thanks for the post.
It really helps lots.
I was trying to use ing the strucutre try to get the image from the imageGallery module.
But from the code shown above, we can only get the url for the image instead of the Image Class Object. so the image will be huge, and cannot be applied for re-size function.
Is there a way we can construct a Image Class with the url we got and re-apply re-size function?!?!Regards
Alex -
Re: Create Array from File Object

7 August 2010 at 12:43am
Yes this function only returns the path as thats what I needed the images paths in an array. You'd need to apply the resize image class first then generate then pull the URL of the resized image. But if you only need it in a template then just run the Image.SetWidth() control and $Attachment.URL will get you the path
| 1509 Views | ||
|
Page:
1
|
Go to Top |



