/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Device(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Device'])) { $model->attributes = $_POST['Device']; $model->status = 1; if (Person::model()->findByPk($model->person_id)->company_id == User::getMyCompany() || Yii::app()->user->role == 1) { if ($model->save()) { $fp = fopen('images/barcode/' . $model->barcode . '.png', 'wb'); // Открываем файл $ch = curl_init("http://barcode.tec-it.com/barcode.ashx?translate-esc=off&data={$model->barcode}&code=Code128&unit=Fit&dpi=96&imagetype=Png&rotation=0&color=000000&bgcolor=FFFFFF&qunit=Mm&quiet=0"); curl_setopt($ch, CURLOPT_FILE, $fp); // Передаём дескриптор файла, туда сбросится результат curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); //Перечмодим файлик chmod('images/barcode/' . $model->barcode . '.png', 0777); //Теперь мы его обрежем, чтобы не нам не мешал водознак UserFunctions::crop('images/barcode/' . $model->barcode . '.png'); $this->redirect(array('view', 'id' => $model->id)); } } else { throw new CHttpException(403, 'Вы не имеете прав в этой организации'); } } $this->render('create', array('model' => $model)); }