Exemple #1
0
 /**
  * 送信されたデータをもとに添付ファイル用の配列を生成して返す
  *
  * @return array $attachments pathの配列
  */
 protected function get_attachments()
 {
     $attachments = array();
     $upload_file_keys = $this->Data->get_post_value_by_key(MWF_Config::UPLOAD_FILE_KEYS);
     if ($upload_file_keys !== null && is_array($upload_file_keys)) {
         $wp_upload_dir = wp_upload_dir();
         foreach ($upload_file_keys as $key) {
             $upload_file_url = $this->Data->get_post_value_by_key($key);
             if (!$upload_file_url) {
                 continue;
             }
             $filepath = MWF_Functions::fileurl_to_path($upload_file_url);
             if (file_exists($filepath)) {
                 $filepath = MWF_Functions::move_temp_file_to_upload_dir($filepath);
                 $new_upload_file_url = MWF_Functions::filepath_to_url($filepath);
                 $this->Data->set($key, $new_upload_file_url);
                 $attachments[$key] = $filepath;
             }
         }
     }
     return $attachments;
 }