試圖在Wordpress中設置一個上傳MIME的循環。我有一個帶逗號分隔列表(option_file_types)的CMS選項,用戶可以在其中指定可以上傳的文件類型列表。但我無法弄清楚如何讓它們全部放入foreach並正確輸出。當不在foreach中時,它可以處理一個文件類型條目。任何幫助將非常感激。Foreach Loop for Wordpress上傳mimes
代碼:
function custom_upload_mimes ($existing_mimes = array()) {
$file_types = get_option('option_file_types');
$array = $file_types;
$variables = explode(", ", $array);
foreach($variables as $value) {
$existing_mimes[''.$value.''] = 'mime/type']);
}
return $existing_mimes;
}
預期輸出:
$existing_mimes['type'] = 'mime/type';
$existing_mimes['type'] = 'mime/type';
$existing_mimes['type'] = 'mime/type';
你能發佈的'$ file_types'值和預期輸出的價值?另外,你現在得到什麼輸出? – Dogbert 2011-03-17 16:59:21
當你回顯'$ file_types'時,你只需要得到逗號分隔的列表..所以基本的文件類型:'pdf,doc,docx,xls,xlsx'。現在,它不輸出任何東西 – 2011-03-17 17:05:37