我正在使用文件模块从本地获取表单中的某些文件并上传到另一台服务器。当我尝试上传大文件时,它给我超时错误(我已经尝试更改php.ini,但这不是我希望它如何工作)。这就是我试图通过ftp函数上传文件的原因。但是,我无法获取我刚刚选择上传的文件的源路径(例如filepath,而不是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!"));
}
} }
答案 0 :(得分:0)
我解决了这个问题。问题主要是因为我把错误的道路作为目标。它必须是/ public_html / ......而不是/ home / our_name / public_html