cakephp 圖片上傳

筆記一下

其實這不是個很標準的cakephp解決方案
但是這是可以用的解決方案

$t_UploadFileName1=$this->data['qu']['pic1path']['tmp_name'];
if (is_uploaded_file($t_UploadFileName1))
{
    srand((double)microtime()*1000000);
   $seed = rand(1000000,9999999);
    srand((double)microtime()*$seed); 
    $uploads_dir="";$t_path="";$rnd="";
    $rnd= rand(100, 999);
    $t_fname=$this->data[' qu']['pic1path']['name'];
    $t_fname=pathinfo($t_fname,PATHINFO_EXTENSION);
    $uploads_dir = WWW_ROOT . '/files/upfiles/';
    $t_path1 = date("YmdHis") .$rnd.".". $t_fname;
    $t_path=$uploads_dir.$t_path1;

    if (move_uploaded_file($t_UploadFileName1, $t_path)) {
        $this->data['Collect_data_qu']['pic1path'] = $t_path1;
    }else{
        $t_fileflg=0;
    }
}else{
    $t_fileflg=0;
}
if ($t_fileflg){
    if ($this-> qu->save($this->data)) {
        //JUST DO IT
    }
}

在預設的FormHelper內,data會是預設的陣列名稱,如果要使用model的save方法時必用
[tmp_name]是暫存檔案名稱
[name]是上傳檔案名稱