저장 방법 uploadfield에 훅하는 것입니다 새 파일을 구문 분석하는 가장 좋은 방법은 FileIframeField을 위해 당신이 할 수있는 하위 그것을 클래스라는 저장 덮어 쓰기하여()
(이 SilverStripe 3 FileIframeField에서 작업을 수행하는 방법에 대한
아래
, 예) $tmpfile = $request->postVar($this->getName());
: UploadField라는 새로운 클래스, UploadField 당신이 UploadField->upload(SS_HTTPRequest $request)
을 덮어해야하고 파일은 다음과 accesable이있을 것입니다
class myFileIFrameField extends FileIFrameField {
public function save($data, $form) {
if (
!isset($data['FileSource'])
|| ($data['FileSource'] == 'new' && (!isset($_FILES['Upload']) || !$_FILES['Upload']))
|| ($data['FileSource'] == 'existing' && (!isset($data['ExistingFile']) || !$data['ExistingFile']))
) {
$form->sessionMessage(_t('FileIFrameField.NOSOURCE', 'Please select a source file to attach'), 'required');
Director::redirectBack();
return;
}
$fileContent = false;
if($data['FileSource'] == 'new') {
$fileContent = file_get_contents($_FILES['Upload']['tmp_name']);
}
elseif($data['FileSource'] == 'existing') {
$fileObject = DataObject::get_by_id('File', $data['ExistingFile']);
$fileContent = file_get_contents($fileObject->getFullPath());
}
if ($fileContent) {
// parse the $fileContent here
}
// if you want to still save the file into a relation,
//meaning if you want to have the actually FileIframeField behaviour still in tact then call
return parent::save($data, $form);
// other wise, if you do not want to save the relation and you don't want to save the file to the server
// thenn do NOT call parent::save, just do:
// Director::redirectBack();
}
}
그래서 sittree 객체 또는 일반 데이터 객체에 대해 complextablefield를 통해 관리하고 있습니까? 행동은 다르다, 나는 생각한다. '페이지'가 즉시 sitetree에 생성 될 때 db에 저장된다. – schellmax
아니요. 죄송합니다. 큰 덩어리의 정보를 남겨 두지 않았습니다. DataObjectManager 및이 업로드 필드가있는 DataObjecta 중 하나를 사용하고 있습니다. – MillyMonster
당신은 당신이 그 파일로 무엇을하고 싶은지에 대해 자세하게 설명 할 수 있습니다. 나는 당신이하려고하는 것을 볼 수 없기 때문에 그것을하기가 어렵습니다. – Zauberfisch