当前位置: 首页>>代码示例>>PHP>>正文


PHP Upload::image方法代码示例

本文整理汇总了PHP中Upload::image方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::image方法的具体用法?PHP Upload::image怎么用?PHP Upload::image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Upload的用法示例。


在下文中一共展示了Upload::image方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save($id, $title, $content, $publish, $image, $stock, $price, $new)
 {
     if (is_array($image)) {
         $imageName = Upload::image($image);
     } else {
         $imageName = $image;
     }
     $db = getDB();
     if ($new) {
         $result = $db->query("INSERT INTO posts (title, content, published, type, featured_image, price ,stock) VALUES ({$title}, {$content}, {$publish}, 'product', {$imageName}, {$price}, ' {$stock}')");
     } else {
         $result = $db->query("UPDATE posts SET title='{$title}', content='{$content}', published='{$publish}', featured_image='{$imageName}', price='{$price}', stock='{$stock}' WHERE id='{$id}'");
     }
 }
开发者ID:eriknu,项目名称:ehandel,代码行数:14,代码来源:Product.php

示例2: action_save

 public function action_save()
 {
     $this->view = NULL;
     $values = $this->request->post();
     if ($values['id'] == 0) {
         $values['id'] = NULL;
     }
     $id = $values['id'];
     $this->response->headers('Content-Type', 'application/json');
     try {
         $check = array('title', 'default');
         $file = array('status' => 'empty', 'msg' => '');
         if (!isset($values['img'])) {
             $cfg = Kohana::$config->load('avatar.size');
             if (!Upload::image($_FILES['img'])) {
                 $file['status'] = 'error';
                 $file['msg'] = 'The supplied image is not uploadable.';
             } elseif (file_exists(DOCROOT . 'assets/img/avatars/' . $_FILES['img']['name'])) {
                 $file['status'] = 'error';
                 $file['msg'] = 'There\'s already an image with the same filename';
             } elseif (!Upload::image($_FILES['img'], $cfg['width'], $cfg['heigth'], TRUE)) {
                 // not the right image dimensions
                 $file = array('status' => 'error', 'msg' => 'You need to provide a valid image (size: :width x :heigth.', array(':width' => $cfg['width'], ':heigth' => $cfg['heigth']));
             }
             Upload::save($_FILES['img'], $_FILES['img']['name'], DOCROOT . 'assets/img/avatars/');
             $values['img'] = $_FILES['img']['name'];
             $check[] = 'img';
         }
         if (!isset($values['default'])) {
             $values['default'] = FALSE;
         }
         $values['default'] = $values['default'] == 'on';
         $avatar = ORM::factory('Avatar', $values['id']);
         $avatar->values($values, $check);
         $avatar->save();
         $data = array('action' => 'saved', 'type' => $id == NULL ? 'new' : 'update', 'row' => array(URL::base() . 'assets/img/avatars/' . $avatar->img, $avatar->title, $avatar->default, $avatar->id));
         $this->response->body(json_encode($data));
     } catch (ORM_Validation_Exception $e) {
         $errors = array();
         $list = $e->errors('models');
         foreach ($list as $field => $er) {
             if (!is_array($er)) {
                 $er = array($er);
             }
             $errors[] = array('field' => $field, 'msg' => $er);
         }
         $this->response->body(json_encode(array('action' => 'error', 'errors' => $errors)));
     }
 }
开发者ID:modulargaming,项目名称:user,代码行数:49,代码来源:Avatars.php

示例3: mysql_fetch_array

 $field_list = 'no_of_student';
 $res = Model::view($table, $condition, $field_list);
 $row = mysql_fetch_array($res);
 $field_list = '*';
 $condition = "batch='" . $_POST['batch_id'] . "'";
 $res = Model::view($tablename, $condition, $field_list);
 $total1 = mysql_num_rows($res);
 $condition = "batch='" . $_POST['batch_id'] . "' and email='" . $_POST['txtemail_id'] . "'";
 $res = Model::view($tablename, $condition, $field_list);
 $total2 = mysql_num_rows($res);
 //if($total==1 && $total2==0 && $total1!=$row['no_of_student'])
 //{
 $start_name = $_POST['txtemail_id'];
 $field = 'upload_photo';
 $dest = '../student/upload_photo';
 $image = Upload::image($field, $dest, $start_name);
 $condition = "ID='" . $_POST['txtname'] . "'";
 $set_value = "contact_person='" . $_POST['txtfathers_name'] . "', image='{$image}', date_of_birth='" . $_POST['year'] . "/" . $_POST['month'] . "/" . $_POST['day'] . "', address='" . $_POST['txtaddress'] . "', contact_no='" . $_POST['txtcontact_no'] . "', email='" . $_POST['txtemail_id'] . "', alt_contact='" . $_POST['txtalt_contact'] . "', password='{$ranStr}', status='" . $_POST['txtplacement_req'] . "', type='st'";
 $r = Model::update($tablename, $set_value, $condition);
 if ($r) {
     $email = $_POST['txtemail_id'];
     $message = "Your Registration Succesfuly! Your Email ID-:" . $email . " and Password-:" . $ranStr;
     $subject = "Registration";
     $mail = new Mail($subject, $message, $email);
     $a = $mail->sendMail();
     if ($a) {
         header("Location:../Main Content/welcome_message.php?title=registration");
     }
 }
 /*}
 else if($total2!=0)
开发者ID:harishankar121,项目名称:gitrepogit,代码行数:31,代码来源:college_registration_php.php

示例4: validImage

 static function validImage($data)
 {
     if (NULL === $data || !Upload::not_empty($data)) {
         return TRUE;
     }
     return Upload::image($data);
 }
开发者ID:vspvt,项目名称:kohana-forms,代码行数:7,代码来源:Field.php

示例5: action_save

 public function action_save()
 {
     if (!$this->user->can('Admin_Item_Shops_Save')) {
         throw HTTP_Exception::factory('403', 'Permission denied to view admin item shops save');
     }
     $this->view = NULL;
     $values = $this->request->post();
     if ($values['id'] == 0) {
         $values['id'] = NULL;
     }
     $id = $values['id'];
     $this->response->headers('Content-Type', 'application/json');
     try {
         // $base_dir = DOCROOT . 'assets' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'items'
         // . DIRECTORY_SEPARATOR . 'shops' . DIRECTORY_SEPARATOR . 'npc' . DIRECTORY_SEPARATOR;
         // $values['npc_img'] = $base_dir . $values['npc_img'];
         $item = ORM::factory('Shop', $values['id']);
         if ($item->loaded()) {
             $img = $item->npc_img;
             $item->values($values, array('title', 'status', 'npc_text', 'stock_type', 'stock_cap'));
         } else {
             $img = NULL;
             $values['npc_img'] = 'tmp';
             $item->values($values, array('title', 'status', 'npc_img', 'npc_text', 'stock_type', 'stock_cap'));
         }
         $item->save();
         $file = array('status' => 'empty', 'msg' => '');
         if (isset($_FILES['image'])) {
             $image = $_FILES['image'];
             $cfg = Kohana::$config->load('items.npc.image');
             if ($img == NULL) {
                 $img = $image['name'];
             }
             if (!Upload::valid($image)) {
                 // error not valid upload
                 $file = array('status' => 'error', 'msg' => 'You did not provide a valid file to upload.');
             } elseif (!Upload::image($image, $cfg['width'], $cfg['height'], TRUE)) {
                 // not the right image dimensions
                 $file = array('status' => 'error', 'msg' => 'You need to provide a valid image (size: :width x :height.', array(':width' => $cfg['width'], ':height' => $cfg['height']));
             } else {
                 $msg = '';
                 if ($id != NULL and $img != NULL and file_exists(DOCROOT . 'media/image/npc/shop/' . $img)) {
                     $grave_dir = DOCROOT . 'media/graveyard/npc/shop/';
                     if (!is_dir($grave_dir)) {
                         mkdir($grave_dir, 0, TRUE);
                     }
                     // move the previously stored item to the graveyard
                     $new_name = Text::random('alnum', 4) . $img;
                     copy(DOCROOT . 'media/image/npc/shop/' . $img, $grave_dir . $new_name);
                     unlink(DOCROOT . 'media/image/npc/shop/' . $img);
                     $msg = 'The old image has been moved to the graveyard and renamed to ' . $new_name;
                 }
                 if (!is_dir(DOCROOT . 'media/image/npc/shop/')) {
                     mkdir(DOCROOT . 'media/image/npc/shop/', 0, TRUE);
                 }
                 $up = Upload::save($image, $image['name'], DOCROOT . 'media/image/npc/shop/');
                 // $up = Upload::save($image, DOCROOT . 'media/image/npc/shop/'.$image['name']);
                 if ($up != FALSE) {
                     $file['status'] = 'success';
                     $file['msg'] = 'You\'ve successfully uploaded your item image';
                     if (!empty($msg)) {
                         $file['msg'] .= '<br />' . $msg;
                     }
                     $item->npc_img = $image['name'];
                     $item->save();
                 } else {
                     $file = array('status' => 'error', 'msg' => 'There was an error uploading your file.');
                 }
             }
         }
         $data = array('action' => 'saved', 'type' => $id == NULL ? 'new' : 'update', 'file' => $file, 'row' => array($item->title, $item->stock_type, $item->status, $item->id));
         $this->response->body(json_encode($data));
     } catch (ORM_Validation_Exception $e) {
         $errors = array();
         $list = $e->errors('models');
         foreach ($list as $field => $er) {
             if (!is_array($er)) {
                 $er = array($er);
             }
             $errors[] = array('field' => $field, 'msg' => $er);
         }
         $this->response->body(json_encode(array('action' => 'error', 'errors' => $errors)));
     }
 }
开发者ID:modulargaming,项目名称:item,代码行数:84,代码来源:Shops.php

示例6: action_colour_update

 public function action_colour_update()
 {
     if (!$this->user->can('Admin_Pet_Specie_Colour_Update')) {
         throw HTTP_Exception::factory('403', 'Permission denied to view admin pets specie colour update');
     }
     $specie = ORM::factory('Pet_Specie', $this->request->post('specie_id'));
     $colour = $this->request->post('colour_id');
     $c = ORM::factory('Pet_Colour', $colour);
     // handle upload
     $file = array('status' => 'empty', 'msg' => '');
     if (isset($_FILES['image'])) {
         $image = $_FILES['image'];
         $cfg = Kohana::$config->load('pet.image');
         // check if the temp dir exists
         if (!file_exists($cfg['tmp_dir'])) {
             mkdir($cfg['tmp_dir']);
         }
         if (!Upload::valid($image)) {
             // error not valid upload
             $file = array('status' => 'error', 'msg' => 'You did not provide a valid file to upload.');
         } elseif (!Upload::image($image, $cfg['width'], $cfg['height'], TRUE)) {
             // not the right image dimensions
             $file = array('status' => 'error', 'msg' => 'You need to provide a valid image (size: :width x :heigth.', array(':width' => $cfg['width'], ':height' => $cfg['height']));
         } else {
             if (!file_exists(DOCROOT . 'media/image/pets/' . $specie->dir)) {
                 mkdir(DOCROOT . 'media/image/pets/' . $specie->dir);
             }
             $msg = '';
             if (file_exists(DOCROOT . 'media/image/pets/' . $specie->dir . $c->image)) {
                 // move the previously stored item to the graveyard
                 $new_name = Text::random('alnum', 4) . $specie->name;
                 copy(DOCROOT . 'media/image/pets/' . $specie->dir . $c->image, DOCROOT . 'assets/graveyard/pets/' . $new_name);
                 unlink(DOCROOT . 'media/image/pets/' . $specie->dir . $c->image);
                 $msg = 'The old image has been moved to the graveyard and renamed to ' . $new_name;
             }
             $up = Upload::save($image, $c->image, DOCROOT . 'media/image/pets/' . $specie->dir);
             if ($up != FALSE) {
                 $file['status'] = 'success';
                 $file['msg'] = 'You\'ve successfully uploaded your pet image';
                 if (!empty($msg)) {
                     $file['msg'] .= '<br />' . $msg;
                 }
             } else {
                 $file = array('status' => 'error', 'msg' => 'There was an error uploading your file.');
             }
         }
     }
     // save colour
     $specie->add('colours', $c);
     $this->response->headers('Content-Type', 'application/json');
     $this->response->body(json_encode($file));
 }
开发者ID:modulargaming,项目名称:pet,代码行数:52,代码来源:Specie.php

示例7: action_save

 public function action_save()
 {
     if (!$this->user->can('Admin_Item_Save')) {
         throw HTTP_Exception::factory('403', 'Permission denied to view admin item save');
     }
     $values = $this->request->post();
     $cfg = Kohana::$config->load('items.image');
     $this->view = NULL;
     if ($values['id'] == 0) {
         $values['id'] = NULL;
     }
     $id = $values['id'];
     $this->response->headers('Content-Type', 'application/json');
     // get the item
     $item = ORM::factory('Item', $values['id']);
     $file = array('status' => 'empty', 'msg' => '');
     $tmp = NULL;
     $upload = NULL;
     if (isset($_FILES['image'])) {
         $image = $_FILES['image'];
         if (!Upload::valid($image)) {
             // error not valid upload
             $file = array('status' => 'error', 'msg' => 'You did not provide a valid file to upload.');
         } elseif (!Upload::image($image, $cfg['width'], $cfg['height'], TRUE)) {
             // not the right image dimensions
             $file = array('status' => 'error', 'msg' => 'You need to provide a valid image (size: :width x :height.', array(':width' => $cfg['width'], ':height' => $cfg['height']));
         } elseif (!Upload::type($image, $cfg['format'])) {
             // not the right image type
             $file = array('status' => 'error', 'msg' => 'You need to provide a valid image (type: :type).', array(':type' => implode(',', $cfg['format'])));
         } else {
             // check if the temp dir exists
             if (!file_exists($cfg['tmp_dir'])) {
                 mkdir($cfg['tmp_dir']);
             }
             // save it temporarily
             $upload = Image::factory($image['tmp_name'])->save($cfg['tmp_dir'] . $image['name'] . Text::random() . '.png');
             $tmp = array('upload' => $upload, 'name' => $image['name']);
             if ($tmp['upload'] != FALSE) {
                 $file['status'] = 'temp';
             } else {
                 $file = array('status' => 'error', 'msg' => 'There was an error uploading your file.');
             }
         }
     }
     if ($file['status'] == 'temp' or $file['status'] == 'empty') {
         try {
             $data = array();
             $type = ORM::factory('Item_Type', $values['type_id']);
             $base_dir = DOCROOT . 'media' . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . 'items' . DIRECTORY_SEPARATOR;
             // if we're just changing the item type we'll have to move it a different dir
             if ($type->id != $item->type_id and $file['status'] == 'empty') {
                 $tmp['upload'] = $base_dir . $item->type->img_dir . $item->img;
                 $tmp['name'] = $item->img;
             }
             // move the file to the correct dir if it's possible
             $new_loc = $base_dir . $type->img_dir . $tmp['name'];
             // check if the dir exists
             if (!file_exists($base_dir . $type->img_dir)) {
                 mkdir($base_dir . $type->img_dir);
             }
             if ($file['status'] == 'empty' and $tmp != NULL and file_exists($new_loc)) {
                 $file = array('status' => 'error', 'msg' => 'That filename already exists');
                 $data['type'] = 'error';
                 $data['errors'] = array();
             } else {
                 // if commands are set parse them
                 if (isset($values['commands'])) {
                     $values['commands'] = Item::parse_commands($values['commands']);
                 }
                 // attempt to save the item
                 if ($tmp != NULL) {
                     $values['image'] = $tmp['name'];
                     $item->values($values, array('name', 'status', 'image', 'description', 'unique', 'transferable', 'type_id', 'commands'));
                     $item->save();
                     // if it's saved move the file to the new location
                     if ($item->saved()) {
                         // move the uploaded file to the correct place with the correct name
                         if ($upload != NULL) {
                             $upload = Image::factory($image['tmp_name'])->save($new_loc);
                         } else {
                             copy($tmp['upload'], $new_loc);
                         }
                         $file['status'] = 'success';
                     }
                 } else {
                     $item->values($values, array('name', 'status', 'description', 'unique', 'transferable', 'type_id', 'commands'));
                     $item->save();
                 }
                 $data['row'] = array($item->img(), $item->name, $item->status, $item->type->name, $item->id);
                 $data['action'] = 'saved';
             }
             $data['type'] = $id == NULL ? 'new' : 'update';
             $data['file'] = $file;
             $this->response->body(json_encode($data));
         } catch (ORM_Validation_Exception $e) {
             $errors = array();
             $list = $e->errors('models');
             foreach ($list as $field => $er) {
                 if (!is_array($er)) {
                     $er = array($er);
//.........这里部分代码省略.........
开发者ID:modulargaming,项目名称:item,代码行数:101,代码来源:Item.php


注:本文中的Upload::image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。