CodeIgniter の使用は初めてです。私の質問がばかげている場合はお詫び申し上げます。
私のモデル関数は次のとおりです。
function entry_insert($fname){
$this->load->database();
$maxFileID=mysql_fetch_array(mysql_query("SELECT max(convert(substring( FileID , 1,length(FileID)-4 ) ,unsigned integer)) as val FROM docrepository"));
// Find the maximum value of FileID
if ($maxFileID['val']==NULL)
{
$temp="1.PDF";
}
else
{
//$data["FileID"]=(string)(intval(substr($row[0],0,-4))+1).".PDF"; // If there is already file
$temp=(string) ($maxFileID['val']+1).".PDF";
}
$data=array(
'FileID' =>$temp,
'FileName' =>$fname,// Not sure whether it will work---I need your suggestion
'title' =>$this->input->post('title'),
'author' =>$this->input->post('author'),
'description' =>$this->input->post('description'),
'companyName' =>$this->input->post('companyName'),
'aircraftModel' =>$this->input->post('aircraftModel'),
'aircraftNumber'=>$this->input->post('aircraftNumber'),
'documentType' =>$this->input->post('documentType'),
'documentNumber'=>$this->input->post('documentNumber'),
'sectionNumber' =>$this->input->post('sectionNumber'),
'dateCreated' =>$this->input->post('dateCreated'),
'keywords' =>$this->input->post('keywords'),
'notes' =>$this->input->post('notes')
);
$this->db->insert('docrepository',$data);
}
すべてのデータはビューの入力フォームから取得されます。
私の目的は、元のファイル名をデータベースに保存し、ファイルをサーバーに特定の形式 (FileID) でアップロードすることです。したがって、この文脈では
- モデルまたはコントローラーのどこに do_upload() 関数を配置する必要がありますか?
- ビューでユーザーがアップロードしたファイル名を取得するにはどうすればよいですか?
- また、do_upload 関数がサーバーにファイルをアップロードできるように、FileID を新しいファイル名として送信する方法を教えてください。
サンプルコードでアイデアをいただければ幸いです。