我已经编写了这些代码来上传文件并使用绑定参数将路径保存在数据库中
$model->attributes=$_POST['Form'];
$uploadedFile=CUploadedFile::getInstance($model,'resume');
$path = '/protected/upload/'.time().$uploadedFile;
if($model->validate()){
$connection=Yii::app()->db;
$filePath=Yii::app()->basePath .DIRECTORY_SEPARATOR.'..'.$path; // file upload location
$result = $uploadedFile->saveAs($filePath); //upload file
// an SQL with placeholders
$hobbies=implode(",",$model->hobbies); // comma deliminated string of hobbies
$dob =date('Y-m-d',strtotime($model->dob)); // convert date
$status=1; // status of record
$sql='INSERT INTO student (name, dob, email, gender, hobbies, city, resume, message,status, created_date,modified_date) VALUES(:name,:dob,:email,:gender,:hobbies,:city,:resume,:msg,:status,now(),now())';
$command=$connection->createCommand($sql);
// replace the placeholder with the actual username value
$command->bindParam(":name",$model->name,PDO::PARAM_STR);
$command->bindParam(":dob",$dob,PDO::PARAM_STR);
$command->bindParam(":email",$model->email,PDO::PARAM_STR);
$command->bindParam(":gender",$model->gender,PDO::PARAM_INT);
$command->bindParam(":hobbies",$hobbies,PDO::PARAM_STR);
$command->bindParam(":city",$model->city,PDO::PARAM_INT);
$command->bindParam(":resume",$path,PDO::PARAM_STR);
$command->bindParam(":msg",$model->msg,PDO::PARAM_STR);
$command->bindParam(":status",$status,PDO::PARAM_INT);
$result=$command->execute();
}
我希望这些对你有用。