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


PHP uploadImage函数代码示例

本文整理汇总了PHP中uploadImage函数的典型用法代码示例。如果您正苦于以下问题:PHP uploadImage函数的具体用法?PHP uploadImage怎么用?PHP uploadImage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _before_update

 /**
  * 修改之前的操作
  * 在修改操作之前先判断是否有图片上传,
  * 有图片上传则删掉之前的图片,保存新的图片;
  * 没有图片上传则保留原来的图片
  */
 protected function _before_update(&$data, $options)
 {
     //判断是否有图片上传
     if (!empty($_FILES['bg_imgpath']['name'])) {
         //获取修改的数据id
         $bg_id = $options['where']['bg_id'];
         //获取改数据的图片路径,并判断是否存在,存在则删除
         $img_path = $this->field('bg_imgpath')->where(array('bg_id' => $bg_id))->find();
         if ($img_path['bg_imgpath']) {
             $path = C('rootPath') . $img_path['bg_imgpath'];
             //拼接图片所在的位置
             @unlink($path);
             //unlink:删除文件的函数  @防止报错
         }
         //图片上传操作
         $config = array('mimes' => array('image/jpg', 'image/png', 'image/jpeg', 'image/gif'), 'rootPath' => C('rootPath'), 'maxSize' => 0, 'savePath' => 'Blog/', 'is_array' => 0);
         //执行上传文件和生成缩略图的操作
         $res = uploadImage('bg_imgpath', $config);
         //判断上述操作是否执行成功
         if ($res['ok'] == 1) {
             //将源图和缩略图的地址存放$data数组中写入数据库
             $data['bg_imgpath'] = $res['img'][0];
         } else {
             //返回上传文件和生成缩略图中产生的错误
             $this->error = $res['error'];
             return false;
         }
     }
 }
开发者ID:xy-lp,项目名称:myblog,代码行数:35,代码来源:BlogModel.class.php

示例2: addToBook

function addToBook()
{
    //set all of the variables
    $address_group_id = filter_input(INPUT_POST, 'address_group_id');
    $fullname = filter_input(INPUT_POST, 'fullname');
    $email = filter_input(INPUT_POST, 'email');
    $address = filter_input(INPUT_POST, 'address');
    $phone = filter_input(INPUT_POST, 'phone');
    $website = filter_input(INPUT_POST, 'website');
    $birthday = filter_input(INPUT_POST, 'birthday');
    //replace the phone number with the appropriate formatting
    $phoneRegex = '/^\\(?([2-9]{1}[0-9]{2})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/';
    $phone = preg_replace($phoneRegex, '($1) $2-$3', $phone);
    if (strlen($fullname) < 1 || strlen($email) < 1 || strlen($address) < 1 || strlen($phone) < 1) {
        return false;
    }
    try {
        $image = uploadImage('upfile');
    } catch (RuntimeException $ex) {
        //echo $ex->getMessage();
        $image = '';
    }
    //connect and set statement
    $db = dbconnect();
    $stmt = $db->prepare("INSERT INTO address SET user_id = :user_id, address_group_id = :address_group_id, fullname = :fullname, email = :email, address = :address, phone = :phone, website = :website, birthday = :birthday, image = :image");
    $binds = array(":user_id" => $_SESSION['user_id'], ":address_group_id" => $address_group_id, ":fullname" => $fullname, ":email" => $email, ":address" => $address, ":phone" => $phone, ":website" => $website, ":birthday" => $birthday, ":image" => $image);
    if ($stmt->execute($binds) && $stmt->rowCount() > 0) {
        return true;
    } else {
        return false;
    }
}
开发者ID:Dayakes,项目名称:PHPWinterCLass2016,代码行数:32,代码来源:Add-functions.php

示例3: update

 public function update($postData, $book_id, $target_dir)
 {
     if (uploadImage($target_dir) !== 'success' && uploadImage($target_dir) !== 'Image is not chosen.') {
         return uploadImage($target_dir);
     } else {
         $postData['image'] = basename($_FILES["image"]["name"]);
         if ($postData['image'] === '') {
             $postData['image'] = $_SESSION['oldImage'];
         }
         db_update($this->table, $postData, 'id=' . $book_id);
         return 'success';
     }
 }
开发者ID:huynhtrucquyen0812,项目名称:EntryBlog,代码行数:13,代码来源:book.php

示例4: ajouterActivite

/**
 * Fonction permettant d'ajouter une activité en base de données grâce aux données d'un formulaire.
 * @return mixed : soit un tableau contenant tous les messages d'erreurs relatif à l'ajout d'activité, soit un tableau
 * contenant un message de succès de l'ajout de l'activité.
 */
function ajouterActivite()
{
    $cat = $_POST['categorie'];
    $act = $_POST['activite'];
    $desc = $_POST['description'];
    $cm = new CategorieManager(connexionDb());
    $am = new ActivityManager(connexionDb());
    $categorie = $cm->getCategorieByLibelle($cat);
    $activityVerif = $am->getActivityByLibelle($act);
    if (strtolower($activityVerif->getLibelle()) == strtolower($act)) {
        $tabRetour['Error'] = "Cette activité existe déjà, ajoutez-en une autre !";
    } else {
        if (strlen($act) >= 5 && strlen($act) <= 100) {
            if (champsTexteValable($desc)) {
                $desc = nl2br($desc);
                $activityToAdd = new Activity(array("Libelle" => $act, "description" => $desc));
                $am->addActivity($activityToAdd);
                $activityToRecup = $am->getActivityByLibelle($act);
                include "../Manager/Categorie_ActivityManager.manager.php";
                $typePhoto = $_FILES['image']['type'];
                if (!strstr($typePhoto, 'jpg') && !strstr($typePhoto, 'jpeg')) {
                    $tabRetour['Error'] = "Votre image n'est pas .jpg ou .jpeg !";
                } else {
                    if ($_FILES['ImageNews']['size'] >= 2097152) {
                        $tabRetour['Error'] = "Votre image est trop lourde !";
                    } else {
                        if ($_FILES['image']['tmp_name'] != null) {
                            uploadImage('../Images/activite', $activityToRecup->getId());
                            $cam = new Categorie_ActivityManager(connexionDb());
                            $um = new UserManager(connexionDb());
                            $um->updateUserLastIdea($_SESSION['User']);
                            $cam->addToTable($activityToRecup, $categorie);
                            $tabRetour['Ok'] = "Votre activité a bien été ajoutée au contenu du site, merci de votre participation !";
                        } else {
                            $tabRetour['Error'] = "Pas d'image !";
                        }
                    }
                }
            } else {
                $tabRetour['Error'] = "Votre description contient des caractères indésirables !";
            }
        } else {
            $tabRetour['Error'] = "Votre titre d'activité n'a pas une taille correcte !";
        }
    }
    return $tabRetour;
}
开发者ID:OvynFlavian,项目名称:IntegrationTP_Groupe_1,代码行数:52,代码来源:ajouterActivite.lib.php

示例5: insertNewMeal

function insertNewMeal($values, $connectionObject)
{
    $fileName = uploadImage("mealPicture", "content/pictures/");
    if ($fileName) {
        $createMealQuery = "INSERT INTO meal VALUES (DEFAULT, :name_, :price, :quantity, :snack, :drink, :picture)";
        $createMealResult = $connectionObject->prepare($createMealQuery);
        $createMealResult->execute(array(':name_' => $values['newMealName'], ':price' => $values['newMealPrice'], ':quantity' => $values['newMealQuantity'], ':snack' => $values['newMealSnack'], ':drink' => $values['newMealDrink'], ':picture' => $fileName));
        if (!$createMealResult) {
            echo "An error occurred.\n";
            error_log("Error on insertNewMeal function");
            return Null;
        }
    } else {
        echo "Error uploading image";
        error_log("Error uploading image");
    }
}
开发者ID:pLesur,项目名称:orgaMIsation,代码行数:17,代码来源:administrationFunctions.php

示例6: index

 public function index()
 {
     $amount = (int) $this->input->get('amount');
     $imagesArray = $this->Image->getImages(0, $amount);
     foreach ($imagesArray as $key => $value) {
         if (file_exists($this->config->item('PATH_IMAGE') . $value->image)) {
             $pathImage = $this->config->item('PATH_IMAGE') . $value->image;
             $result = uploadImage(['PATH_IMAGE' => $pathImage, 'PATH_COOKIE' => $this->config->item('PATH_COOKIE'), 'title' => $value->title]);
             sleep(30);
             unlink($pathImage);
             $this->Image->deleteImage($value->id);
         }
     }
     print_r($imagesArray);
     //        $this->output
     //            ->set_status_header($result['status'])
     //            ->set_output(json_encode($result['data']));
 }
开发者ID:sasha8-1,项目名称:instagram,代码行数:18,代码来源:UploadImage.php

示例7: uploadImage

function uploadImage($conf, $depth = 0)
{
    $depth = (int) $depth;
    $depth = $depth + 1;
    $result = postingImage($conf);
    print_r($result);
    if ($result['status'] != 200 && $depth < 3) {
        // hack
        file_get_contents("http://localhost/instagram/index.php/GetCookie/");
        return uploadImage($conf, $depth);
    } else {
        if ($result['status'] != 200 && $depth >= 3) {
            log_message('error', 'Don\'t upload Image');
            //        throw new Exception('Error');
        } else {
            return $result;
        }
    }
}
开发者ID:sasha8-1,项目名称:instagram,代码行数:19,代码来源:upload_helper.php

示例8: admin_edit

 /**
  * @param null $id
  * Cette méthode permet d'editer et d'enregistrer, selon qu'on ait le ID ou pas
  */
 public function admin_edit($id = null)
 {
     $this->loadModel('Offreancia');
     //on charge le controller qu'on veut éditer
     $this->Offreancia->changeID();
     $d['id'] = '';
     if ($this->request->data) {
         //debug($_FILES['IMAGE']['name']);
         if (!empty($_FILES['IMAGE']['name'])) {
             $imageValid = uploadImage('IMAGE');
             if ($imageValid['ok']) {
                 $this->request->data->IMAGE = $imageValid['chemin'];
                 // debug($this->request->data);
                 // die();
             } else {
                 echo '<script>alert("' . $imageValid['msg'] . '")</script>';
             }
         }
         if ($this->Offreancia->validates($this->request->data)) {
             if ($this->Offreancia->save($this->request->data)) {
                 $this->Session->setFlash('le contenu a bien été modifié', 'success');
             }
             //  die($id=$this->Post->id);
             //echo("ajouté ou modifié");
         } else {
             $this->Offreancia->save($this->request->data);
             $this->Session->setFlash('Merci de corriger vos informations', 'danger');
         }
     }
     if ($id) {
         $id = intval($id);
         $this->request->data = $this->Offreancia->findOne(array('conditions' => array('ID_OFFRE_ANCIA' => $id)));
         $d['id'] = $id;
     }
     $this->loadModel('Utilisateur');
     $this->Utilisateur->changeID();
     $d['utilisateurs'] = $this->Utilisateur->find(array());
     $this->loadModel('Client');
     $this->Client->changeID();
     $d['clients'] = $this->Client->find(array());
     $this->set($d);
 }
开发者ID:ronaldodia,项目名称:backend_al,代码行数:46,代码来源:OffreanciasController.php

示例9: uploadPhoto

function uploadPhoto($ip, $image, $nick, $email, $path, $albumName)
{
    $existsAlbum = isAlbum($nick, $albumName);
    if (!$existsAlbum) {
        if (!newAlbum($ip, $nick, $email, $albumName, "private", "DEFAULT")) {
            return '1';
        }
    }
    if (uploadImage($image, $path)) {
        $newPhoto = addPhoto($nick, $path, $albumName);
        if (!newPhoto and !$existsAlbum) {
            deleteAlbum($nick, $albumName);
            // Remove Photo
            return '2';
        }
        addAction($nick, $email, $ip, 'new_photo');
        return '0';
    }
    return '3';
}
开发者ID:jagumiel,项目名称:bigou-Album,代码行数:20,代码来源:photo_logic.php

示例10: modifyCategory

function modifyCategory()
{
    $catId = (int) $_GET['catId'];
    $name = $_POST['txtName'];
    $description = $_POST['mtxDescription'];
    $image = $_FILES['fleImage'];
    $catImage = uploadImage('fleImage', SRV_ROOT . 'images/category/');
    // if uploading a new image
    // remove old image
    if ($catImage != '') {
        _deleteImage($catId);
        $catImage = "'{$catImage}'";
    } else {
        // leave the category image as it was
        $catImage = 'cat_image';
    }
    $sql = "UPDATE tbl_category \n               SET cat_name = '{$name}', cat_description = '{$description}', cat_image = {$catImage}\n               WHERE cat_id = {$catId}";
    $result = dbQuery($sql) or die('Cannot update category. ' . mysql_error());
    header('Location: index.php');
}
开发者ID:joevanni,项目名称:gallantic-shopping-cart,代码行数:20,代码来源:processCategory.php

示例11: product_update

function product_update()
{
    $id = $_POST['id'];
    if (isset($_POST['update'])) {
        $data['product_object'] = model('product')->getOne($id);
        //var_dump($data);die;
        $data['template_file'] = 'product/update.php';
        render('layout.php', $data);
    }
    if (isset($_POST['saveUpdate'])) {
        unset($_POST['saveUpdate']);
        $postData = postData();
        if ($_FILES["fileImage"]['name'] != "") {
            $postData['image'] = uploadImage();
            deleteImage($_POST['image']);
        }
        if (model('product')->updateProduct($postData, $id)) {
            redirect('/index.php?c=product&m=list');
        }
    }
}
开发者ID:nguyenlevietphi,项目名称:MyBlog,代码行数:21,代码来源:product.php

示例12: mysql_select_db

mysql_select_db($database, $dbConn);
$transaccion = $_POST['transaccion'];
switch ($transaccion) {
    case 'INSERT':
        // Obtiene de la base de datos el último id de los celulares
        $query_newId = "SELECT (MAX(id_celular) + 1) as newId FROM celularesMasPopulares";
        $newId = mysql_query($query_newId, $dbConn) or die(mysql_error());
        $row_newId = mysql_fetch_assoc($newId);
        $id_celular = $row_newId["newId"];
        $dir_celular = "../../uploads/celulares_mas_populares/" . $id_celular . "/";
        $filename = NULL;
        if ($_FILES['foto']['tmp_name'] != NULL) {
            $filename = uploadImage("foto", $dir_celular, 120, 248);
        }
        $sql = sprintf("INSERT INTO celularesMasPopulares(id_celular, nombre, foto) VALUES(%s, %s, %s)", GetSQLValueString($id_celular, "int"), GetSQLValueString(utf8_decode($_POST['nombre']), "text"), GetSQLValueString($filename, "text"));
        echo "{$sql}";
        break;
    case 'UPDATE':
        $dir_celular = "../../uploads/celulares_mas_populares/" . $_POST['id_celular'] . "/";
        $filename = NULL;
        if ($_FILES['foto']['tmp_name'] != NULL) {
            $filename = uploadImage("foto", $dir_celular, 120, 248);
        } else {
            $filename = $_POST['foto_actual'];
        }
        $sql = sprintf("UPDATE celularesMasPopulares SET nombre=%s, foto=%s WHERE id_celular=%s", GetSQLValueString(utf8_decode($_POST['nombre']), "text"), GetSQLValueString($filename, "text"), GetSQLValueString($_POST['id_celular'], "int"));
        break;
}
// switch
$result = mysql_query($sql, $dbConn) or die(mysql_error());
mysql_free_result($result);
开发者ID:designomx,项目名称:eligefacil,代码行数:31,代码来源:saveCelularData.php

示例13: date

              <?php 
if (isset($_POST['sg'])) {
    if (!empty($_FILES['thumb']['tmp_name'])) {
        $pasta = "../upload/";
        $ano = date('Y');
        $mes = date('m');
        if (!file_exists($pasta . $ano) && is_dir($pasta . $ano)) {
            mkdir($pasta . $ano, 0755);
        }
        if (!file_exists($pasta . $ano . '/' . $mes)) {
            mkdir($pasta . $ano . '/' . $mes, 0755);
        }
        $img = $_FILES['thumb'];
        $ext = substr($img['name'], -3);
        $thumb = $ano . '/' . $mes . '/' . setUri($img['name']);
        uploadImage($img['tmp_name'], setUri($img['name']), '600', $pasta . $ano . '/' . $mes . '/');
    }
    $d = date('Y-m-d H:i:s');
    $campos = array('post_id' => $postId, 'img' => $thumb, 'data' => $d);
    create("galeria", $campos);
}
?>
        
              <?php 
// deleta imagem no bando e na pasta upload
if (!empty($_GET['iddel'])) {
    $iddel = $_GET['iddel'];
    $img = $_GET['img'];
    $pasta = $pasta = "../upload/";
    if (file_exists($pasta . $img)) {
        unlink($pasta . $img);
开发者ID:wilsonazer,项目名称:santodaime,代码行数:31,代码来源:gallery.php

示例14: elseif

         } elseif (!valMail($f['email'])) {
             echo '<span class="ms al">Atenção: O e-mail informado nao tem um formato válido!</span>';
         } elseif (strlen($f['code']) < 8 || strlen($f['code']) > 12) {
             echo '<span class="ms no">Erro: A senha deve ter entre 8 e 12 caracteres!</span>';
         } else {
             if (!empty($_FILES['avatar']['tmp_name'])) {
                 $imagem = $_FILES['avatar'];
                 $pasta = '../uploads/avatars/';
                 if (file_exists($pasta . $user['avatar']) && !is_dir($pasta . $user['avatar'])) {
                     unlink($pasta . $user['avatar']);
                 }
                 $tmp = $imagem['tmp_name'];
                 $ext = substr($imagem['name'], -3);
                 $nome = md5(time()) . '.' . $ext;
                 $f['avatar'] = $nome;
                 uploadImage($tmp, $nome, 200, $pasta);
             }
             unset($f['date']);
             unset($f['statusS']);
             update('up_users', $f, "id = '{$userEditId}'");
             $_SESSION['return'] = '<span class="ms ok">Usuário atualizado com sucesso!</span>';
             header('Location: index2.php?exe=usuarios/usuarios-edit&userid=' . $userEditId);
         }
     } elseif (!empty($_SESSION['return'])) {
         echo $_SESSION['return'];
         unset($_SESSION['return']);
     }
     ?>
 <form name="formulario" action="" method="post" enctype="multipart/form-data">
     <label class="line">
         <span class="data">Nome:</span>
开发者ID:CivalCs,项目名称:ProPHP,代码行数:31,代码来源:usuarios-edit.php

示例15: getAddressGroups

<?php 
$addressGroups = getAddressGroups();
$newAddressData = array();
if (isPostRequest()) {
    $newAddressData[0] = $_SESSION['currentUserID'];
    $newAddressData[1] = filter_input(INPUT_POST, 'selected_address_group');
    $newAddressData[2] = filter_input(INPUT_POST, 'fullname');
    $newAddressData[3] = filter_input(INPUT_POST, 'email');
    $newAddressData[4] = filter_input(INPUT_POST, 'address');
    $newAddressData[5] = formatPhone(stripPhone(filter_input(INPUT_POST, 'phone')));
    $newAddressData[6] = filter_input(INPUT_POST, 'website');
    $newAddressData[7] = filter_input(INPUT_POST, 'birthday');
    $errors = validation($newAddressData);
    if (count($errors) == 0) {
        $newAddressData[8] = uploadImage();
        if (empty($newAddressData[8])) {
            $errors[] = 'Image could not be uploaded';
            $results = 'Empty Image';
        }
        if (createContact($newAddressData)) {
            $results = 'New item added to address book';
        } else {
            $results = 'Item was not Added';
        }
    } else {
        $results = 'Errors found';
    }
}
?>
开发者ID:NWhitaker27,项目名称:PHPClassSummer2015,代码行数:29,代码来源:add.php


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