コード例 #1
0
 public function actionAjax_upload_doc($id, $type)
 {
     if (isset($_GET['title'])) {
         $_SESSION['title'] = strip_tags(trim($_GET['title']));
         die;
     }
     $model = $this->loadModel($id);
     if ($model) {
         $totalImgupload = ProListingUploadCea::model()->countByAttributes(array('listing_id' => $id));
         if (!ProListingUploadCea::checkLimitFileUpload($id)) {
             $result['errorMesage'] = 'Limit ' . LIMIT_DOC_UPLOAD . ' file upload';
             die(json_encode($result));
         }
         //upload file ajax
         Yii::import("ext.EAjaxUpload.qqFileUploader");
         $ImageProcessing = new ImageProcessing();
         $ImageProcessing->createSingleDirectoryByPath("/upload/listing/{$id}");
         $ImageProcessing->createSingleDirectoryByPath("/upload/listing/{$id}/cea");
         $folder = "upload/listing/{$id}/cea/";
         $allowedExtensions = array("doc", "docx", "xls", "xlsx", "pdf", "csv");
         $sizeLimit = 5 * 1024 * 1024;
         // maximum file size in bytes
         $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
         $result = $uploader->handleUpload($folder, true);
         $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
         $fileSize = filesize($folder . $result['filename']);
         //GETTING FILE SIZE
         $fileName = $result['filename'];
         //GETTING FILE NAME
         if (isset($result['success']) && $result['success'] == true) {
             $cea = new ProListingUploadCea();
             $cea->listing_id = $id;
             $cea->file = $fileName;
             $cea->title = isset($_SESSION['title']) ? $_SESSION['title'] : '';
             $cea->created_date = date('Y-m-d h:i:s');
             $cea->validate();
             if ($cea->save()) {
                 unset($_SESSION['title']);
             }
         }
         echo $return;
         // it's array
         //            if (isset($_FILES['Listing']) && isset($_POST['Listing']['title_cea'])) {
         //                $totalImgupload = ProListingUploadCea::model()->countByAttributes(array('listing_id' => $id));
         //                if (!ProListingUploadCea::checkLimitFileUpload($id)) {
         //                    echo "limit";
         //                    die();
         //                }
         //                $data = CUploadedFile::getInstances($model, 'file_upload');
         //                if ($_POST['Listing']['title_cea'] != '' && !empty($data)) {
         //                    foreach ($data as $k => $file) {
         //                        $name = date('d-m-Y-h-i-s') . "." . $file->getExtensionName();
         //                        $cea = new ProListingUploadCea();
         //                        $cea->attributes = $_POST['Listing'];
         //                        $cea->listing_id = $id;
         //                        $cea->file_upload = $file;
         //                        $cea->file = $name;
         //                        $cea->title = isset($_POST['Listing']['title_cea']) ? $_POST['Listing']['title_cea'] : '';
         //                        $cea->created_date = date('Y-m-d h:i:s');
         //                        $cea->validate();
         //                        if ($cea->save()) {
         //                            $ImageProcessing = new ImageProcessing();
         //                            $ImageProcessing->createSingleDirectoryByPath("/upload/listing/$id");
         //                            $ImageProcessing->createSingleDirectoryByPath("/upload/listing/$id/cea");
         //                            $file->saveAs(YII_UPLOAD_DIR . "/listing/$id/cea/$name");
         //                        }
         //                    }
         //                }
         //            }
     }
 }
コード例 #2
0
 public function actionAjax_upload_doc($id)
 {
     $model = $this->loadModel($id);
     if ($model) {
         if (isset($_FILES['Listing']) && isset($_POST['Listing']['title_cea'])) {
             $totalImgupload = ProListingUploadCea::model()->countByAttributes(array('listing_id' => $id));
             if (!ProListingUploadCea::checkLimitFileUpload($id)) {
                 die("limit");
             }
             $data = CUploadedFile::getInstances($model, 'file_upload');
             if ($_POST['Listing']['title_cea'] != '' && !empty($data)) {
                 foreach ($data as $k => $file) {
                     $name = date('d-m-Y-h-i-s') . "." . $file->getExtensionName();
                     $cea = new ProListingUploadCea();
                     $cea->attributes = $_POST['Listing'];
                     $cea->listing_id = $id;
                     $cea->file_upload = $file;
                     $cea->file = $name;
                     $cea->title = isset($_POST['Listing']['title_cea']) ? $_POST['Listing']['title_cea'] : '';
                     $cea->created_date = date('Y-m-d h:i:s');
                     $cea->validate();
                     if ($cea->hasErrors()) {
                         die('maxsize');
                     } else {
                         if ($cea->save()) {
                             $ImageProcessing = new ImageProcessing();
                             $ImageProcessing->createSingleDirectoryByPath("/upload/listing/{$id}");
                             $ImageProcessing->createSingleDirectoryByPath("/upload/listing/{$id}/cea");
                             $file->saveAs(YII_UPLOAD_DIR . "/listing/{$id}/cea/{$name}");
                         }
                     }
                 }
             }
         }
     }
 }