나는 몇 주 전에 비슷한 것을해야했고 Remote File module에서 일부 기능, 특히 remote_file_cck_attach_file()
기능을 채택했습니다. 이 함수는 filefield 모듈의 field_file_save_file()
함수를 사용합니다.이 함수는 찾고있는 함수 일 수 있습니다.
내 경우 파일은 여러 원격 위치에서 가져와 file_save_data()
을 사용하여 일시적으로 저장됩니다.
public static function attachAsCCKField(&$node, $filepath, $fieldname, $index=0) {
// Grab the filefield definition
$field = content_fields($fieldname, $node->type);
$validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
$fieldFileDirectory = filefield_widget_file_path($field);
// This path does not necessarily exist already, so make sure it is available
self::verifyPath($fieldFileDirectory);
$file = field_file_save_file($filepath, $validators, $fieldFileDirectory);
// Is the CCK field array already available in the node object?
if (!is_array($node->$fieldname)) {
// No, add a stub
$node->$fieldname=array();
}
$node->{$fieldname}[$index] = $file;
}
$filepath
이 연결해야 파일의 경로, $fieldname
노드와 $index
내에서 사용할 수있는 FileField와 인스턴스의 내부 이름입니다하십시오 CCK의 및 FileField에 부착하는 것은 다음 사용 hook_nodeapi()
프리 세이브에서 발생 여러 개의 필드 항목이있는 경우 첨부 파일의 0 기반 색인이됩니다.
함수는 유틸리티 클래스 내에서 끝났으므로 verifyPath() 호출에 대한 클래스 구문이 사용됩니다. 이 호출은 대상 디렉토리가 사용 가능한지 확인합니다.
public static function verifyPath($path) {
if (!file_check_directory($path, FILE_CREATE_DIRECTORY)) {
throw new RuntimeException('The path "' . $path . '" is not valid (not creatable, not writeable?).');
}
}
그게 나를 위해 해 줬어. 자동으로 노드를 저장하면 다른 일이 생겼어.
아직 getid3 모듈을 사용하지 않았으므로이 방법과 함께 사용할 것인지 잘 모르겠습니다. 또한 파일 필드에 추가 정보/속성을 추가 할 필요가 없으므로 field_file_save_file()
에 의해 반환 된 파일보다 필드 배열에 더 많은 정보를 넣어야합니다. 어쨌든, 이것이 도움이되고 행운이 있기를 바랍니다.
field_file_save_file()에 +1하면 시간이 절약되었습니다. –
매우 유망 해 보입니다. 마감 기한이 없다면 즉시 파고 들려고합니다. – googletorp