에 가이드 및 다운로드 파일을 볼 수 있습니다 YII
간단한 업로드 파일의 동작을 썼다 바인드 매개 변수 사용
$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();
}
이 정보가 유용 할 것입니다.
필요에 따라 번호를 추가하십시오. 간단합니다. 어서, 당신은 그것을 만들 수 있습니다! – hakre
@hakre 나는 동일한 이름의 파일이 해당 디렉토리에 존재하는 경우에만 번호 매기기를 추가해야한다는 의미입니다. 나는 그것을 처리 할 수있는 함수가 내장되어 있는지 묻는 것입니다. 그렇지 않으면 유효한 파일 이름에 도달 할 때까지 file_exists() 검사를 수행하고 파일 이름에 번호를 반복해야합니다. Yii가 그것을 처리 할 수 있다면 너무 좋았을 것입니다. – ajaybc
그런 다음 YII API 문서를 확인하십시오. 그거 했니? – hakre