2011-01-26 4 views
0

이 스크립트를 사용하여 파일을 Drupal에 업로드하려고합니다. Drupal의 파일 시스템이 비공개로 설정되었습니다.프로그래밍 방식으로 파일을 Drupal에 업로드, 파일 시스템을 비공개로 설정

노드가 잘 생성되고 어떤 이유로 인해 모든 기능이 작동하지 않습니다. 첨부 된 파일을 다운로드 할 수 없습니다. 그냥 페이지를 찾을 수 없게됩니다. drupal에서 노드를 만들고 파일을 업로드하면 정상적으로 작동합니다.

여기 내 코드에 문제가있을 것입니다. 나는 파일을 업로드하기 위해 this guide을 따르고 있었지만 Drupal의 파일 시스템을 개인용으로 설정하고 누군가 프로그래밍 방식으로 제대로 작동하게하려면 무엇을해야하는지 모르는 것 같습니다.

누구나이 경험이 있습니까?

//prep file source and destination vars 
$withoutExt = substr($file2, 0, -7); 
$sourcePDF = "/var/www/html/pay.***.com/burst_pdfs/pdfs/" . $withoutExt . ".pdf"; 
$destinationPDF = '/var/paystubs/' . $drupalUid . '/' . $withoutExt . '.pdf'; 
$destination = '/var/paystubs/' . $drupalUid . '/'; 

//if the file does not exist, create it 
if (!file_check_directory($destination, TRUE)){ 
    echo "Fail";  
} 

// Copy the file to the Drupal files directory if it exists 
if (file_exists($sourcePDF)) { 

    if(!file_move($sourcePDF, $destination, FILE_EXISTS_RENAME)) { 
     echo "Failed to move file: $sourcePDF.\n"; 
    } 
} else { 

    echo "File Moved to " . $destination . "<br/>"; } 


$mime = 'application/pdf'; // Importing PDF files 
$file = new stdClass(); 
$file->filename = $withoutExt; 
$file->filepath = $destinationPDF; 
$file->filemime = $mime; 
$file->filesize = filesize($destinationPDF); 

$file->uid = 1; 
$file->status = FILE_STATUS_PERMANENT; 
$file->timestamp = time(); 
drupal_write_record('files', $file);  



$node = new stdClass(); 
$node->title = $employeeDate; 
$node->body = $employeeID; 
$node->type = 'estub'; 
$node->uid = 1; 

//$field = field_file_save_file($file_drupal_path, file_directory_path() .'/'. $directory); 
//$node->$field_paystub_upload[] = $field; 

$node->field_estub_upload = array(
    array(
     'fid' => $file->fid, 
     'title' => basename($file->filename), 
     'filename' => $file->filename, 
     'filepath' => $file->filepath, 
     'filesize' => $file->filesize, 
     'mimetype' => $mime, 
     'data' => array(
     'description' => $withoutExt, 
    ), 
     'list' => 1, 
    ), 
); 

    $node->status = 1; 
    $node->active = 1; 
    $node->promote = 1; 
    node_save($node); 

답변

0

내 첫번째 추측은 파일 드루팔가에 액세스 할 수 있도록하기위한 "파일"디렉토리에 있어야한다는 것입니다. /var/paystubs/$uid은 Drupal의 "files"디렉토리로 설정되어 있습니까? 인터페이스를 사용하여 파일을 업로드하면 결국 /var/paystubs/$uid이 표시됩니다.

+0

예. 사용자 uid를 찾기 위해 db 쿼리를 사용하고 있습니다. –

+0

테스트를 할 때 인터페이스와 코드를 사용하면 파일 시스템의 파일 (권한 포함), 파일 테이블의 행 및 노드의 devel 출력이 동일합니까? 내 다음 추측은 파일 시스템의 사용 권한입니다. – mirzu

+0

노드를 만들 때 파일이 올바르게 링크되지 않습니다. –

관련 문제