0

我正在使用文件模块从本地表单中获取一些文件并上传到另一台服务器。当我尝试上传大文件时,它给了我超时错误(我尝试更改 php.ini 但这不是我希望它工作的方式)。这就是我尝试通过 ftp 函数上传文件的原因。但是,我无法获取刚刚选择上传的文件的源路径(例如文件路径,而不是 uri)。我想将此文件路径作为源传递给 fopen() 函数。但我不断收到错误:*ftp_nb_fput() [function.ftp-nb-fput]:无法打开该文件:assets_managed_file_form_upload_submit() 中没有这样的文件或目录(FILE_DIRECTORY 的第 303 行)。*

function assets_managed_file_form_upload_submit($form, &$form_state) {
   for ($i = 0; $i < $form_state['num_files']; $i++) {
   if ($form_state['values']['files_fieldset']['managed_field'][$i] != 0) {

  // Make the file permanent.
  $file = file_load($form_state['values']['files_fieldset']['managed_field'][$i]);

  $local_path = file_create_url($file->uri);
  //drupal_set_message(t("file->uri: " . $file->uri . "    local path: " . $local_path));

  $file->status = FILE_STATUS_PERMANENT;
  $directory = 'private://cubbyhouse/'. $form_state['values']['allowed_user'];
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY);


    $source = fopen($local_path,"r");

    $conn = ftp_connect("FTP SERVER") or die("Could not connect");
    ftp_login($conn,"USERNAME", "PASS");
    $ftp_directory = TheDirectoryIwantToPutTheFile . $form_state['values']['allowed_user'];

    $uri_parts = explode("/",$file->uri);
    $filename = $uri_parts[sizeof($uri_parts)-1];
    $target = $ftp_directory . "/" . $filename;
    //drupal_set_message(t($target . " " . $file->uri));
    $ret = ftp_nb_fput($conn,$target,$source,FTP_ASCII);

    while ($ret == FTP_MOREDATA)
    {
       // Do whatever you want
       //echo ".";
       // Continue upload...
       $ret = ftp_nb_continue($conn);
    }
    ftp_close($conn);


  //$file->uri = file_unmanaged_copy($file->uri, $directory, FILE_EXISTS_REPLACE);
  $file->uid = $form_state['values']['allowed_user'];
  drupal_chmod($file->uri);
  file_save($file);

  // Need to add an entry in the file_usage table.
  file_usage_add($file, 'assets', 'image', 1);

  drupal_set_message(t("Your file has been uploaded!"));
}

} }

4

1 回答 1

0

我解决了这个问题。问题主要是因为我给了错误的路径作为目标。它必须是 /public_html/...... 而不是 /home/our_name/public_html

于 2013-06-13T00:52:11.840 回答