Example #1
0
 /**
  * 上传图片
  **/
 function actionuploadimg()
 {
     $ret = array('status' => 0, 'msg' => '');
     try {
         $skc = Yii::app()->request->getParam('skc');
         $sku = Yii::app()->request->getParam('sku');
         $img_type = Yii::app()->request->getParam('img_type');
         $orderid_str = Comm::strdecipher(Yii::app()->request->getParam('orderid_str'));
         $id = Comm::strdecipher(Yii::app()->request->getParam('id'));
         $order_ret = orderclass::selectOrderNameByOrderID($_SESSION['brandid'], array($orderid_str));
         if (count($order_ret) == 0) {
             throw new Exception('订单查询失败');
         }
         $img_name = $_FILES['facebox_file']['name'];
         $images = Common::upload('facebox_file', 'uploads/');
         if ($images == '文件为空' || $images == "文件太大" || $images == '只能上传图像' || $images == '上传图片失败') {
             //表示页面图片更改过
             throw new Exception($images);
         }
         $file = 'orderlist/' . $order_ret[0]['ordername'] . '/' . $sku . '/' . $skc . '/' . ($img_type == 1 ? 'product' : ($img_type == 3 ? 'model' : 'details')) . '/' . $img_name;
         $clothesimage = new clothesimageclass();
         $img_ret = $clothesimage->select_all_image($id, '-1', array('url' => $file));
         if (count($img_ret) > 0) {
             @unlink($_SERVER['DOCUMENT_ROOT'] . '/' . $images);
             throw new Exception('图片已存在');
         }
         //上传到服务器上的临时文件名
         $uploadfile_ret = $this->qinuu_upload($file, $_SERVER['DOCUMENT_ROOT'] . '/' . $images);
         //if(!isset($uploadfile_ret[0]['hash'])){
         //@unlink($_SERVER['DOCUMENT_ROOT'].'/'.$images);
         //	throw new Exception('图片上传失败');
         //}
         $clothesimage->create_clothes_img($img_name, $img_type, $file, $id, '');
         @unlink($_SERVER['DOCUMENT_ROOT'] . '/' . $images);
         $ret['status'] = 1;
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     //echo '<script>parent.facebox_upload_img_ret(\''.json_encode($ret).'\')</script>';
 }