您在這裡

不管什麼檔案格式後面都是/index.html並且另開視窗超連結~

我想修改upload模組的檔傳上傳完的格式為
以下格式~不管什麼檔案格式後面都是/index.html並且另開視窗超連結~

找到相關修改程式的地方~但怎修改都沒法修到像上圖這樣的格式~請求大家指點了~
非常感謝~

if (!empty($node->files) && is_array($node->files)) {
$form['files']['#theme'] = 'upload_form_current';
$form['files']['#tree'] = TRUE;
foreach ($node->files as $key => $file) {
$file = (object)$file;
$description = file_create_url($file->filepath); (建立檔案上傳路徑)
$description = "". check_plain($description) ."";
$form['files'][$key]['description'] = array('#type' => 'textfield', '#default_value' => !empty($file->description) ? $file->description : $file->filename, '#maxlength' => 256, '#description' => $description );
$form['files'][$key]['size'] = array('#value' => format_size($file->filesize));
$form['files'][$key]['remove'] = array('#type' => 'checkbox', '#default_value' => !empty($file->remove));
$form['files'][$key]['list'] = array('#type' => 'checkbox', '#default_value' => $file->list);
$form['files'][$key]['weight'] = array('#type' => 'weight', '#delta' => count($node->files), '#default_value' => $file->weight);
$form['files'][$key]['filename'] = array('#type' => 'value', '#value' => $file->filename);
$form['files'][$key]['filepath'] = array('#type' => 'value', '#value' => $file->filepath);
$form['files'][$key]['filemime'] = array('#type' => 'value', '#value' => $file->filemime);
$form['files'][$key]['filesize'] = array('#type' => 'value', '#value' => $file->filesize);
$form['files'][$key]['fid'] = array('#type' => 'value', '#value' => $file->fid);
$form['files'][$key]['new'] = array('#type' => 'value', '#value' => FALSE);
}
}

附加檔案大小
Image icon 未命名111.JPG6.05 KB

看不太懂
你是要改這個地方下載的連結

還是這個地方顯示的連結阿

hom您好:
是啊~要改掉那裡的超連結~不管什麼格式都只變成檔名\index.html並超連結。
主要是因為我有一個zip檔,裡面是一個網頁(index.html)
所以就想說如果我將一個zip上傳,之後我把它的附檔名全部改為以下格式。
http://127.0.0.1/d6m01/file/download/2/api key/index.html (應為api key.txt但加上反斜線然後統一名稱index.html)

-------------------------------------------------------------------------------------

而之後像有一堆zip檔時,再於系統建立一個批次檔,定時將zip解壓縮,這樣子~就能達到上面的方式…
但試著修改程式…就不知怎下手改成此格式了~~

---------------------------------------------------------------------------------------------
不知那行也試一個個移掉~
$form['files'][$key]['size'] = array('#value' => format_size($file->filesize));(格式大小)
$form['files'][$key]['remove'] = array('#type' => 'checkbox', '#default_value' => !empty($file->remove)); (核取方塊+檔案移除)
$form['files'][$key]['list'] = array('#type' => 'checkbox', '#default_value' => $file->list);(核取方塊+檔案列表)
$form['files'][$key]['weight'] = array('#type' => 'weight', '#delta' => count($node->files), '#default_value' => $file->weight);

你修改的部份只有動到圖二的路徑文字
基本上只要變更 $description = file_create_url($file->filepath); 的字串內容就可以了
但實際上這邊的路徑只是單純的文字顯示,並非超連結

要變更圖一的部份
必須要透過 nodeapi 於 load 階段 修改 $node->files 內的 filepath 來調整路徑
或是透過套版覆寫 theme_upload_attachments 來變更路徑的顯示

hom您好:
是指修改以下這個地方的嘛~
但不知要怎下手改~~

/**
* Implementation of hook_nodeapi().
*/
function upload_nodeapi(&$node, $op, $teaser) {
switch ($op) {

case 'load':
$output = '';
if (variable_get("upload_$node->type", 1) == 1) {
$output['files'] = upload_load($node);
return $output;
}
break;

case 'view':
if (isset($node->files) && user_access('view uploaded files')) {
// Add the attachments list to node body with a heavy
// weight to ensure they're below other elements
if (count($node->files)) {
if (!$teaser && user_access('view uploaded files')) {
$node->content['files'] = array(
'#value' => theme('upload_attachments', $node->files),
'#weight' => 50,
);
}
}
}
break;

是指下面這兩行嘛?但hom我找不到去那修改修改 $node->files 內的 filepath
因為都沒法將副檔名全部改為例:a.zip改為a/index.html

改成 $text = $file->/index.html ;
結果"Parse error: syntax error, unexpected '/', expecting T_STRING or T_VARIABLE or '{' or '$' in D:\AppServ\www\acdactive\sites\all\themes\rootcandy\template.php on line 618
想說指定檔名然後就是全部加上/和index.html

-------------------------------------------------------------------------------------------------------------
function phptemplate_upload_attachments($files) {
$items = array();
foreach ($files as $file) {
$file = (object)$file;
if ($file->list && empty($file->remove)) {
$extension = strtolower(substr(strrchr($file->filename, '.'), 1));
$href = file_create_url($file->filepath);
$text = $file->description ? $file->description : $file->filename;
$items[] = array(
'data' => l($text, $href) .' - '. format_size($file->filesize),
'class' => 'mime-'. $extension,

);
}
}
if (count($items)) {
return theme('item_list', $items, $title = NULL, $type = 'ul', array('class' => 'attachment-list', 'id' => 'attachments'));
}
}

你的程式有錯誤 字串沒有用引號包起來
還有
$text 是連結顯示的文字
$href 才是下載的路徑

試試在 $href = file_create_url($file->filepath);
上面插入一行 $file->filepath = str_replace('.zip', '/index.html', $file->filepath);
這樣應該只會改到原本上傳的是 .zip 的附加檔案

想詢問~
自已加上解壓縮程式~但一點作用也沒~~也沒錯誤訊息~是用法不對嘛? =_="
而且在php.ini中也有開啟php_zip.dll~

/**
* Implementation of hook_nodeapi().
*/
function upload_nodeapi(&$node, $op, $teaser) {
switch ($op) {

case 'load':
$output = '';
if (variable_get("upload_$node->type", 1) == 1) {
$output['files'] = upload_load($node);
return $output;
}
break;

case '.zip':
if (class_exists('ZipArchive')) {
$zip = new ZipArchive;
if ($zip->open($fpath) === TRUE) {
$zip->extractTo($files_dir);
$zip->close();
}
else {
form_set_error('files', t('The uploaded file was not a zip archive.'));
}
}
else {
drupal_set_message("php does not have built in zip support using system call to the unzip binary".'status');
`unzip $fpath -d $files_dir`;
}

`rm $fpath`;
break;