3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 721 Views |
-
Rename image on upload

26 April 2011 at 11:21pm Last edited: 26 April 2011 11:22pm
Hi guys,
What's the best way to rename an image on upload? I'd like to prefix image names with a unique id which matches the related dataobject's ID as they are uploaded.
These images will be downloaded via FTP to perform bulk actions against after a period of time, and they need an identifier to link them to the dataobject with which they were uploaded.
-
Re: Rename image on upload

27 April 2011 at 3:22am Last edited: 27 April 2011 3:30am
Okay, so I was able to do this by extending SimpleImageField (which extends FileField) and overriding FileField's saveInto() method like so:
public function saveInto(DataObject $record) {
...
$id = $_POST['id'];
$filearr = $_FILES[$this->name];
$ext = explode('.',$filearr['name']);
$filearr['name'] = $id.'.'.strtolower(end($ext));
$this->upload->loadIntoFile($filearr, $file, $this->folderName);...
}It works as I'd like for the front-end form, but isn't ideal as if images are uploaded via ModelAdmin, they're not renamed, so would appreciate suggestions for a more robust solution.
-
Re: Rename image on upload

5 October 2012 at 12:25pm
Coudl you paste here all code SimpleImageField with your correction ( with saveInto() )?
Sorry for my bad English
| 721 Views | ||
|
Page:
1
|
Go to Top |


