So I have managed to get the file uploader working but I do not know how to link the resulting file with a an object field "Image". I can see the file appearing on the server but I can not establish a link between the file and dataobject instance field. I have tried using uploadfield but it just crashes so I decided to stick with a filefield.
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Forgot to call write.......
Nope still a problem,
if(isset($data["LIDs"])) {
echo $member->LinkToID->URL."|";
$upload = new Upload();
$f = new Image();
$f->OwnerID = $member->ID;
$f->setFilename("IDS_".$member->ID);
$upload->loadIntoFile($data["LIDs"],$f,"IDS");
$f->write();
if($upload->isError()){
var_dump($up->getErrors());
}else{
Filesystem::sync();
$member->LinkToID = $f;
echo $member->LinkToID->URL."|";
echo $f->URL."|";
echo "|";
$member->write();
echo $member->LinkToID->URL."|";
}
}
File uploads, It seem to link but when I try write it is not saved afterwards....
Hi Liutauras, if you just do this (for now) does the image upload with the original filename and do you get a record in the DB?
if(isset($data["LIDs"])) {
$upload = new Upload();
$image = new Image();
$upload->loadIntoFile($data["LIDs"],$image,"IDS");
} else {
echo "No File Data";
}
The image get uploaded under files tabs in the admin panel and if I use echo $image->ID; I get the id of the file so it is stored in db too.
This is a wild guess but have you tried image->Link?
Just tried the ->Link, didn't work. Thanks for suggestion cause I'm of ideas on this one.