function updateNews($id) { $error = 0; if (isset($_POST)) { $timestamp = date('Y-m-d G:i:s'); $_POST['created_date'] = $timestamp; $this->loadModel('Newsmanager'); $arr['conditions'] = array('id' => $id); $list = $this->Newsmanager->find('all', $arr); //echo $list['Newsmanager']['image'];die(); foreach ($list as $a) { $a['Newsmanager']['slider']; $a['Newsmanager']['image_file']; $a['Newsmanager']['audio']; } if (isset($_FILES['image_file']['name']) && $_FILES['image_file']['name']) { $images = $_FILES['image_file']['name']; $arr = explode('.', $images); $ext = end($arr); $rand = rand(100000, 999999) . '_' . rand(100000, 999999) . '.' . $ext; if ($ext == 'jpg' || $ext == 'JPGE' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif' || $ext == 'JPG' || $ext == 'PNG' || $ext == 'GIF') { $mainimage = APP . '/webroot/news/image/main/' . $rand; $largeimage = APP . '/webroot/news/image/thumb/' . $rand; $smallimage = APP . '/webroot/news/image/thumb1/' . $rand; $croppedimage = APP . '/webroot/news/image/croppedimage/' . $rand; $deletelarge = APP . '/webroot/news/image/thumb/' . $a['Newsmanager']['image_file']; $deletesmall = APP . '/webroot/news/image/thumb1/' . $a['Newsmanager']['image_file']; $deletecropped = APP . '/webroot/news/image/croppedimage/' . $a['Newsmanager']['image_file']; $deletemain = APP . '/webroot/news/image/main/' . $a['Newsmanager']['image_file']; } else { $this->Session->setFlash('Invalid Image Extension'); $error++; } $_POST['image_file'] = $rand; } if ($_FILES['audio']['name']) { $audio = $_FILES['audio']['name']; $arr = explode('.', $audio); $ext = end($arr); $randd = rand(100000, 999999) . '_' . rand(100000, 999999) . '.' . $ext; if ($ext == 'mp3' || $ext == 'wav') { $path1 = APP . '/webroot/news/audio/' . $randd; if ($a['Newsmanager']['audio']) { $delaudio = APP . '/webroot/news/audio/' . $a['Newsmanager']['audio']; } else { $delaudio = ''; } } $_POST['audio'] = $randd; } if (isset($_FILES['slider']['name']) && $_FILES['slider']['name']) { $slider = $_FILES['slider']['name']; if (!empty($_FILES['slider']['name'])) { $arr = explode('.', $slider); $ext = end($arr); $rand2 = rand(100000, 999999) . '_' . rand(100000, 999999) . '.' . $ext; if ($ext == 'jpg' || $ext == 'JPGE' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif' || $ext == 'JPG' || $ext == 'PNG' || $ext == 'GIF') { $path2 = APP . '/webroot/slider/main/' . $rand2; $pathslide = APP . 'webroot/slider/' . $rand2; $delslider = APP . '/webroot/slider/' . $a['Newsmanager']['slider']; $delslidermain = APP . '/webroot/slider/main/' . $a['Newsmanager']['slider']; } } $_POST['slider'] = $rand2; } if ($error == 0) { /* -------------Image Upload----------------*/ if (isset($_FILES['image_file']['name']) && $_FILES['image_file']['name']) { $x1 = $_POST['x1']; $y1 = $_POST['y1']; $w = $_POST['w']; $h = $_POST['h']; unlink($deletesmall); unlink($deletelarge); unlink($deletecropped); unlink($deletemain); // unlink($delimg); move_uploaded_file($_FILES['image_file']['tmp_name'], $mainimage); $resizeObj = new resize($mainimage); $resizeObj->resizeImage($w, $h, 'exact', $_POST['x1'], $_POST['y1']); $resizeObj->saveImage($croppedimage, 100); unset($resizeObj); $resizeObj = new resize($croppedimage); $resizeObj->croppedimage(600, 400, 'exact'); $resizeObj->saveImage($largeimage, 100); unset($resizeObj); $resizeObj = new resize($croppedimage); $resizeObj->croppedimage(300, 200, 'exact'); $resizeObj->saveImage($smallimage, 100); unset($resizeObj); } /* -------------slider Upload----------------*/ if (isset($_FILES['slider']['name']) && $_FILES['slider']['name']) { unlink($delslider); unlink($delslidermain); move_uploaded_file($_FILES['slider']['tmp_name'], $path2); $resizeObj = new resize($path2); $resizeObj->resizeImage(980, 290, 'exact'); $resizeObj->saveImage($pathslide, 100); } /* -------------audio Upload----------------*/ if (isset($_FILES['audio']['tmp_name']) && $_FILES['audio']['tmp_name']) { if ($delaudio != '') { // die('yes audio'); unlink($delaudio); } else { // die('no audio'); } move_uploaded_file($_FILES['audio']['tmp_name'], $path1); } $this->Newsmanager->id = $id; $this->Newsmanager->save($_POST); $this->loadModel('News_category'); $cat = $_POST['category']; $cc = ''; $this->calldeletenewsCategory($id); foreach ($cat as $ca) { $arr1['cat_id'] = $ca; $arr1['news_id'] = $id; $this->News_category->create(); $this->News_category->save($arr1); } $this->Session->setFlash('News have been succesfully updated'); $this->redirect('news'); } } }