public function processFilesAction($image_ad_id) { $request = $this->getRequest(); if ($request->isPost()) { //if there is a post, then lets roll //create array for exchange data - will be used later to save data to DB $exchange_data = array(); // Fetch Configuration from Module Config //fo now we want to get location for temp folder (files uploaded before resize) $targetPath = 'images/tmp_data/'; //there are 9 images from form - lets put them in an array $images_form = array('ad_main_img', 'image_2', 'image_3', 'image_4', 'image_5', 'image_6', 'image_7', 'image_8', 'image_9'); //foreach image copy image, rename and resize foreach ($images_form as $img) { //if there is an image, then go on if (!empty($_FILES[$img]['name'])) { $time = time(); // to randomize file name $random_name = $time . $_FILES[$img]['name']; $targetFileName = $targetPath . $random_name; //a) copy file, if success then go on if (move_uploaded_file($_FILES[$img]['tmp_name'], $targetFileName)) { // b) add data to exchange_data array (later this will be saved to DB) // ex. $exchange_data['image_2'] = $copied_image['name'] $exchange_data[$img] = $random_name; // c) resize and copy to final destination folder //first get extenstion of file $new_img_ext = strtolower(pathinfo($targetFileName, PATHINFO_EXTENSION)); // d) resize :) $this->resizeAction($new_img_ext, $targetFileName, $random_name); } } } //when there is data in an array, then save it to the DB if (!empty($exchange_data)) { $image = new Image(); $exchange_data['image_ad_id'] = $image_ad_id; $image->exchangeArray($exchange_data); $imageTable = $this->getServiceLocator()->get('ImageTable'); $imageTable->saveUpload($image); $ad = new Ad(); $ad->exchangeArray($exchange_data); $adTable = $this->getServiceLocator()->get('AdTable'); $adTable->updateAdMainImage($ad, $image_ad_id); } } return true; }
public function processFilesAction($image_ad_id) { $request = $this->getRequest(); if ($request->isPost()) { //if there is a post, then lets roll //create array for exchange data - will be used later to save data to DB $exchange_data = array(); // Fetch Configuration from Module Config //fo now we want to get location for temp folder (files uploaded before resize) $uploadPath = $this->getTmpFileUploadLocation(); // Save Uploaded file - configure adapter to save files $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setDestination($uploadPath); //$adapter->setDestination('http://scarto.com/images/tmp_data'); //there are 9 images from form - lets put them in an array $images_form = array('ad_main_img', 'image_2', 'image_3', 'image_4', 'image_5', 'image_6', 'image_7', 'image_8', 'image_9'); //foreach image copy image, rename and resize foreach ($images_form as $img) { //get images parameters (names etc.) $current_image = $this->params()->fromFiles($img); //if there is an image, then go on if (!empty($current_image['name'])) { //a) copy file, if success then go on if ($adapter->receive($current_image['name'])) { // b) rename file: $time = time(); // to randomize file name $old_file = $uploadPath . '/' . $current_image['name']; $new_file_name = $time . $current_image['name']; $new_file = $uploadPath . '/' . $new_file_name; rename($old_file, $new_file); // c) add data to exchange_data array (later this will be saved to DB) // ex. $exchange_data['image_2'] = $copied_image['name'] $exchange_data[$img] = $new_file_name; // d) resize and copy to final destination folder //first get extenstion of file $new_img_ext = strtolower(pathinfo($new_file, PATHINFO_EXTENSION)); // resize :) $this->resizeAction($new_img_ext, $new_file, $new_file_name); } } } //when there is data in an array, then save it to the DB if (!empty($exchange_data)) { $image = new Image(); $exchange_data['image_ad_id'] = $image_ad_id; $image->exchangeArray($exchange_data); $imageTable = $this->getServiceLocator()->get('ImageTable'); $imageTable->saveUpload($image); $ad = new Ad($exchange_data); $ad->exchangeArray($exchange_data); $adTable = $this->getServiceLocator()->get('AdTable'); $adTable->updateAdMainImage($ad, $image_ad_id); } } return false; }