/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $input = Request::all();
     // dd($input);
     $pic = new Pic();
     $pic->id_cus = $input['id_cus'];
     $pic->namapic = $input['namapic'];
     $pic->tlppic = $input['tlppic'];
     $pic->emailpic = $input['namapic'];
     $pic->namatgs = $input['nmptgs'];
     $pic->save();
     return Redirect::to('customer/create');
 }
Beispiel #2
0
 /**
  * 微信处理图片
  */
 public static function fitImage($obj, Users $user)
 {
     #判断图片是否开启
     $pic_save_status = Yii::app()->cache->get("qys_pic_save_" . $user->user_id);
     $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $user->user_id));
     if ($pic_save_status == false) {
         $content = "没有开启保存图片功能,该图片不会被服务器保存.";
     } elseif ($count >= 20) {
         $content = "图片已经超过20张,不再做保存。";
     } else {
         $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $user->user_id));
         #获得图片地址
         $pic = file_get_contents($obj->PicUrl);
         $picname = time() . "_" . $user->user_id . ($count + 1) . ".gif";
         $pic_path = Yii::getPathOfAlias('webroot') . '/date/uplaod/';
         $pic_show_path = '/date/uplaod/';
         file_put_contents($pic_path . $picname, $pic);
         if (file_exists($pic_path . $picname)) {
             #小图保存
             $simage = Yii::app()->image->load($pic_path . $picname);
             $simage->resize(80, 80);
             $simage->save($pic_path . "s_" . $picname);
             #中图保存
             $mimage = Yii::app()->image->load($pic_path . $picname);
             $mimage->resize(240, 240);
             $mimage->save($pic_path . "m_" . $picname);
             #大图保存
             $bimage = Yii::app()->image->load($pic_path . $picname);
             $bimage->save($pic_path . "b_" . $picname);
             $userPic = new Pic();
             $picArray = array('user_id' => $user->user_id, 'pic_type' => 0, 'pic_s_img' => $pic_show_path . "s_" . $picname, 'pic_m_img' => $pic_show_path . "m_" . $picname, 'pic_b_img' => $pic_show_path . "n_" . $picname);
             $userPic->setAttributes($picArray);
             if ($userPic->validate() && $userPic->save()) {
                 $content = "图片已经保存。";
             } else {
                 $content = "图片保存失败,请重新发送。";
             }
         } else {
             $content = "保存失败。";
         }
         unlink($pic_path . $picname);
     }
     WechatCheck::_transmitText($obj, $content);
 }
Beispiel #3
0
function save_pic($url, $nick, $comment, $saved_file, $ext)
{
    global $fetch_log;
    $file_name = md5_file($saved_file);
    $path = STORAGE_PATH . $file_name . '.' . $ext;
    rename($saved_file, $path);
    $thumb_path = THUMB_PATH . $file_name . '.jpg';
    list($w, $h) = create_thumb($path, $thumb_path);
    chmod($path, 0664);
    chmod($thumb_path, 0664);
    $pic = new Pic(array('nick' => $nick, 'original_url' => $url, 'path' => $path, 'comment' => $comment, 'thumb' => $thumb_path, 'width' => $w, 'height' => $h, 'ctime' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME'])));
    if (ORM::all('pic', array('checksum' => $pic->checksum))->count() === 0) {
        if ($pic->save()) {
            file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\tpic save SUCCESS\t{$url}\n", FILE_APPEND);
        } else {
            file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\terror saving image: " . var_export($pic->errors(), true) . "\t{$url}\n", FILE_APPEND);
        }
    } else {
        file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\tduplicate image\t{$url}\n", FILE_APPEND);
    }
}