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


PHP SimpleImage::getWidth方法代码示例

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


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

示例1: uploadFile

 protected function uploadFile()
 {
     if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $this->path)) {
         $path = $this->path;
         if (!$this->db->query("INSERT photo (name,folder,time,status) \n\t\t\tVALUES ('" . $this->name . "','" . $this->folder . "','" . time() . "','temp')")) {
             die("error");
         }
         $id = $this->db->getLastId();
         $this->image->load($path);
         $full = new SimpleImage();
         $full->load($path);
         if ($full->getWidth() > 1200) {
             $full->resizeToWidth(1200);
         }
         $full->save(str_replace('.', '.full.', $path));
         if ($this->image->getWidth() > 600) {
             $this->image->resizeToWidth(600);
         }
         $this->image->save($path);
         $size = $this->f->getFullSize($path, 90, 90);
         $img = array('name' => $this->name, 'path' => $path, 'count' => $this->getNum(), 'width' => $size['width'], 'height' => $size['height'], 'id' => $id);
         echo json_encode($img);
     } else {
         echo "error";
     }
 }
开发者ID:Sywooch,项目名称:dump,代码行数:26,代码来源:upload.php

示例2: resizeImagesInFolder

function resizeImagesInFolder($dir, $i)
{
    if (!is_dir('cover/' . $dir)) {
        toFolder('cover/' . $dir);
    }
    $files = scandir($dir);
    foreach ($files as $key => $file) {
        if ($file != '.' && $file != '..') {
            if (!is_dir($dir . '/' . $file)) {
                echo $dir . '/' . $file;
                $image = new SimpleImage();
                $image->load($dir . '/' . $file);
                if ($image->getHeight() < $image->getWidth()) {
                    $image->resizeToWidth(1920);
                } else {
                    $image->resizeToHeight(1920);
                }
                // $new = 'cover/' . $dir . '/'.$image->name;
                if ($i < 10) {
                    $new = 'cover/' . $dir . '/00' . $i . '.' . $image->type;
                } elseif ($i < 100) {
                    $new = 'cover/' . $dir . '/0' . $i . '.' . $image->type;
                } else {
                    $new = 'cover/' . $dir . '/' . $i . '.' . $image->type;
                }
                $image->save($new);
                echo ' ---------> ' . $new . '<br>';
                $i++;
            } else {
                resizeImagesInFolder($dir . '/' . $file, 1);
            }
        }
    }
}
开发者ID:locnd,项目名称:demo,代码行数:34,代码来源:resize.php

示例3: uploadArquivo

    function uploadArquivo($campoFormulario, $idGravado) {
        $ext = pathinfo($_FILES[$campoFormulario][name], PATHINFO_EXTENSION);

        if (($_FILES[$campoFormulario][name] <> "") && ($_FILES[$campoFormulario][size]) > 0 && in_array(strtolower($ext), $this->extensions)) {
            $arquivoTmp = $_FILES[$campoFormulario]['tmp_name'];
            $nome = str_replace(".", "", microtime(true)) . "_" . $_FILES[$campoFormulario]['name'];

            if (function_exists("exif_imagetype")) {
                $test = exif_imagetype($arquivoTmp);
                $image_type = $test;
            } else {
                $test = getimagesize($arquivoTmp);
                $image_type = $test[2];
            }


            if (in_array($image_type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP))) {
                $image = new SimpleImage();
                $image->load($arquivoTmp);
                $l = $image->getWidth();
                $h = $image->getHeight();
                if ($l > $h) {
                    $funcao = "resizeToWidth";
                    $novoTamanho = 1024;
                } else {
                    $funcao = "resizeToHeight";
                    $novoTamanho = 768;
                }

                $image->$funcao($novoTamanho);
                $copiou = $image->save($this->diretorio . $nome);

                if ($this->prefixoMarcaDagua) {
                    $image->$funcao(300);
                    $image->watermark();
                    $image->save($this->diretorio . $this->prefixoMarcaDagua . $nome);
                }
                if ($this->prefixoMiniatura) {
                    $image->load($arquivoTmp);
                    $image->$funcao(380);
                    $image->save($this->diretorio . $this->prefixoMiniatura . $nome);
                }
            } else {
                $copiou = copy($arquivoTmp, $this->diretorio . $nome);
            }
            if ($copiou) {
                $sql = "update $this->tabela set $this->campoBD = '$nome' where id='$idGravado'";
                #$altualizaNome = mysql_query($sql) or die($sql . mysql_error);
                $this->conexao->executeQuery($sql);
            }
        } else {
            return false;
        }
        return $idGravado;
    }
开发者ID:jhmachado,项目名称:anotation,代码行数:55,代码来源:Upload.php

示例4: base64ToLocalImage

 private static function base64ToLocalImage($img, $path, $lim = false, $saveas = '', $quality = 75)
 {
     $imgdata = base64_decode($img);
     if (!!$imgdata) {
         require_once 'Master/base/libraries/Images/SimpleImage.php';
         $str = str_replace('data:', '', $img);
         $arr = explode(';', $str);
         $type = $arr[0];
         $data = str_replace('base64,', '', $arr[1]);
         $data = base64_decode($data);
         $ext = static::getExt($type);
         if (!!$data && !!$ext) {
             $name = !!$saveas ? $saveas : Bella::createId(32);
             $name .= $ext;
             $file = $path . $name;
             $save = @file_put_contents($file, $data);
             if (!!$save) {
                 $sm = new SimpleImage();
                 $sm->load($file);
                 $w = $sm->getWidth();
                 $h = $sm->getHeight();
                 $minWidth = static::MIN_WIDTH;
                 $minHeight = static::MIN_HEIGHT;
                 $maxWidth = static::MAX_WIDTH;
                 $maxHeight = static::MAX_HEIGHT;
                 if (!!$lim) {
                     if (isset($lim['minWidth'])) {
                         $minWidth = $lim['minWidth'];
                     }
                     if (isset($lim['minHeight'])) {
                         $minHeight = $lim['minHeight'];
                     }
                     if (isset($lim['maxWidth'])) {
                         $maxWidth = $lim['maxWidth'];
                     }
                     if (isset($lim['maxHeight'])) {
                         $maxHeight = $lim['maxHeight'];
                     }
                 }
                 if ($w < $minWidth || $h < $minHeight) {
                     unlink($file);
                     return false;
                 }
                 if ($w > $maxWidth || $h > $maxHeight) {
                     $sm->fillTo($maxWidth, $maxHeight);
                     $sm->save($file, false, $quality);
                 }
                 return $name;
             }
         }
     }
 }
开发者ID:ndaidong,项目名称:bella.php,代码行数:52,代码来源:Photo.php

示例5: bindImage

 public function bindImage($elementName)
 {
     $file = JRequest::getVar($elementName, '', 'FILES');
     if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
         return false;
     }
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     // @task: Test if the folder containing the badges exists
     if (!JFolder::exists(DISCUSS_BADGES_PATH)) {
         JFolder::create(DISCUSS_BADGES_PATH);
     }
     // @task: Test if the folder containing uploaded badges exists
     if (!JFolder::exists(DISCUSS_BADGES_UPLOADED)) {
         JFolder::create(DISCUSS_BADGES_UPLOADED);
     }
     require_once DISCUSS_CLASSES . '/simpleimage.php';
     $image = new SimpleImage();
     $image->load($file['tmp_name']);
     if ($image->getWidth() > 64 || $image->getHeight() > 64) {
         return false;
     }
     $storage = DISCUSS_BADGES_UPLOADED;
     $name = md5($this->id . DiscussHelper::getDate()->toMySQL()) . $image->getExtension();
     // @task: Create the necessary path
     $path = $storage . '/' . $this->id;
     if (!JFolder::exists($path)) {
         JFolder::create($path);
     }
     // @task: Copy the original image into the storage path
     JFile::copy($file['tmp_name'], $path . '/' . $name);
     // @task: Resize to the 16x16 favicon
     $image->resize(DISCUSS_BADGES_FAVICON_WIDTH, DISCUSS_BADGES_FAVICON_HEIGHT);
     $image->save($path . '/' . 'favicon_' . $name);
     $this->avatar = $this->id . '/' . $name;
     $this->thumbnail = $this->id . '/' . 'favicon_' . $name;
     return $this->store();
 }
开发者ID:BetterBetterBetter,项目名称:B3App,代码行数:38,代码来源:badges.php

示例6: mkdir

 $tempFile = $_FILES['Filedata']['tmp_name'];
 $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/rb72aknjykn0w5cefu6z3g7yw8xnpa/';
 $targetFile = str_replace('//', '/', $targetPath) . $file;
 $name = $_FILES['Filedata']['name'];
 error_reporting(0);
 // $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
 // $fileTypes  = str_replace(';','|',$fileTypes);
 // $typesArray = split('\|',$fileTypes);
 // $fileParts  = pathinfo($_FILES['Filedata']['name']);
 // if (in_array($fileParts['extension'],$typesArray)) {
 // Uncomment the following line if you want to make the directory if it doesn't exist
 mkdir(str_replace('//', '/', $targetPath), 0755, true);
 move_uploaded_file($tempFile, $targetFile);
 $image = new SimpleImage();
 $image->load($targetFile);
 if ($image->getWidth() > 600 || $image->getHeight() > 450) {
     //set proper width
     if ($image->getWidth() > 600) {
         $image->resizeToWidth(600);
     }
     //set proper height
     if ($image->getHeight() > 450) {
         $image->resizeToHeight(450);
     }
     $image->save($targetFile, IMAGETYPE_JPEG, 75, 0755);
     $newFile = str_replace('//', '/', $targetPath) . 'thumb_' . $file;
     $image->resize(155, 115);
     $image->save($newFile, IMAGETYPE_JPEG, 75, 0755);
 } else {
     $image->save($targetFile, IMAGETYPE_JPEG, 75, 0755);
     $newFile = str_replace('//', '/', $targetPath) . 'thumb_' . $file;
开发者ID:redhattaccoss,项目名称:Qalanjo,代码行数:31,代码来源:photos_uploadify.php

示例7: save

 /**
  * Get file (photo) from POST and save it
  * following the http://forum.joomla.org/viewtopic.php?t=650699 guidelines... override save on model... 
  */
 public function save($data)
 {
     if (empty($data['userid'])) {
         //that means NON mobile.json version (mobile.json sends uid already filled)
         $data = JRequest::getVar('jform', array(), 'post', 'array');
         $uidPath = JFactory::getUser()->get('id');
     } else {
         $uidPath = $data['userid'];
     }
     $file = JRequest::getVar('jform', array(), 'files', 'array');
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $approval = $params->get('approveissue');
     $data['state'] = !$approval;
     if ($approval == 1) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_IMPROVEMYCITY_APPROVAL_PENDING'));
     }
     if ($file) {
         //Cannot use makeSafe with non-english characters (or better only ascii is supported)
         //$filename = JFile::makeSafe($file['name']['photo']);
         //use custom makeSafe instead...
         $filename = $this->stringURLSafe($file['name']['photo']);
         if ($filename != '') {
             if ($file['type']['photo'] != 'image/jpeg' && $file['type']['photo'] != 'image/png') {
                 $this->setError(JText::_('ONLY_PNG_JPG'));
                 return false;
             }
             $src = $file['tmp_name']['photo'];
             $dest = JPATH_SITE . DS . "images" . DS . "improvemycity" . DS . $uidPath . DS . "images" . DS . $filename;
             $thumb_dest = JPATH_SITE . DS . "images" . DS . "improvemycity" . DS . $uidPath . DS . "images" . DS . "thumbs" . DS . $filename;
             //resize image here
             include_once JPATH_COMPONENT . '/helpers/simpleimage.php';
             $image = new SimpleImage();
             $image->load($src);
             $width = $image->getWidth();
             $height = $image->getHeight();
             $new_height = $height;
             $new_width = $width;
             $target_width = 800;
             //TODO: GET FROM PARAMETERS
             $target_height = 600;
             //TODO: GET FROM PARAMETERS
             $target_ratio = $target_width / $target_height;
             $img_ratio = $width / $height;
             if ($target_ratio > $img_ratio) {
                 $new_height = $target_height;
                 $new_width = $img_ratio * $target_height;
             } else {
                 $new_height = $target_width / $img_ratio;
                 $new_width = $target_width;
             }
             if ($new_height > $target_height) {
                 $new_height = $target_height;
             }
             if ($new_width > $target_width) {
                 $new_height = $target_width;
             }
             if ($width > $target_width && $height > $target_height) {
                 if ($new_height != $height || $new_width != $width) {
                     $image->resize($new_width, $new_height);
                     $image->save($src);
                 }
             }
             //always use constants when making file paths, to avoid the possibilty of remote file inclusion
             if (!JFile::upload($src, $dest)) {
                 echo JText::_('ERROR MOVING FILE');
                 return;
             } else {
                 // success, exit with code 0 for Mac users, otherwise they receive an IO Error
                 JPath::setPermissions($dest);
                 //CREATE THUMBNAIL HERE
                 $image->load($dest);
                 $image->resize(80, 60);
                 //TODO: GET FROM PARAMETERS
                 $pathToThumb = JPATH_SITE . DS . 'images' . DS . 'improvemycity' . DS . $uidPath . DS . 'images' . DS . 'thumbs';
                 if (!JFolder::exists($pathToThumb)) {
                     JFolder::create($pathToThumb);
                 }
                 //$thumb = $pathToThumb.DS.$fileName;
                 $image->save($thumb_dest);
                 JPath::setPermissions($thumb_dest);
                 //update data with photo path
                 $data['photo'] = 'images/improvemycity/' . $uidPath . '/images/thumbs/' . $filename;
                 //$data['thumb'] = 'images/improvemycity/'.J$uidPath.'/images/thumbs/'.$filename;
                 //$data['photo'] = 'images'.'/'.'improvemycity'.'/'.$uidPath.'/'.'images'.'/'.$fileName;
             }
             /*
             if (JFile::upload($src, $dest, false) ){
             	//update data with photo path
             	$data['photo'] = 'images/improvemycity/'.$uidPath.'/images/'.$filename;
             } 
             */
         }
     }
     // Initialise variables;
     $dispatcher = JDispatcher::getInstance();
//.........这里部分代码省略.........
开发者ID:Ayner,项目名称:Improve-my-city,代码行数:101,代码来源:addissue.php

示例8: addPictures

function addPictures($categoryid)
{
    global $db, $login, $config;
    $c = (int) $categoryid;
    $category = getCategory($c);
    $folder = $category['uniqid'];
    $path = 'media/images/' . $folder . '/';
    @mkdir($path, 0777);
    @chmod($path, 0777);
    $upload = new Upload();
    $upload->dir = $path;
    if ($config->get('media', 'max-upload-size') > 0) {
        $upload->max_byte_size = $config->get('media', 'max-upload-size');
    } else {
        $upload->max_byte_size = 10485760;
    }
    $result = $upload->uploadArray();
    // Resize image if too large
    if ($config->get('media', 'auto-resize') != 0) {
        $max_width = (int) $config->get('media', 'auto-resize-width');
        if ($max_width == 0) {
            $max_width = 1024;
        }
        $image = new SimpleImage();
        for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
            if (file_exists($path . $_FILES['file']['name'][$i])) {
                $image->load($path . $_FILES['file']['name'][$i]);
                if ($image->getWidth() > $max_width) {
                    $image->resizeToWidth($max_width);
                    unlink($path . $_FILES['file']['name'][$i]);
                    $image->save($path . $_FILES['file']['name'][$i]);
                }
            }
        }
    }
}
开发者ID:tech-nik89,项目名称:lpm4,代码行数:36,代码来源:media.function.php

示例9: mkdir

 if (!is_dir(AT_PA_CONTENT_DIR . $album_file_path_tn)) {
     mkdir(AT_PA_CONTENT_DIR . $album_file_path_tn);
 }
 //add the photo
 $added_photo_id = $pa->addPhoto($_FILES['photo']['name'], $_POST['photo_comment'], $_SESSION['member_id']);
 if ($added_photo_id <= 0) {
     $msg->addError('PA_ADD_PHOTO_FAILED');
 }
 if (!$msg->containsErrors()) {
     //get photo filepath
     $photo_info = $pa->getPhotoInfo($added_photo_id);
     $photo_file_path = getPhotoFilePath($added_photo_id, $_FILES['photo']['name'], $photo_info['created_date']);
     //resize images to a specific size, and its thumbnail
     $si = new SimpleImage();
     $si->load($_FILES['photo']['tmp_name']);
     $image_w = $si->getWidth();
     $image_h = $si->getHeight();
     //picture is horizontal
     if ($image_w > $image_h) {
         //don't stretch images
         if ($image_w > AT_PA_IMAGE) {
             $si->resizeToWidth(AT_PA_IMAGE);
             $si->save(AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path);
         } else {
             move_uploaded_file($_FILES['photo']['tmp_name'], AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path);
         }
         $si->resizeToWidth(AT_PA_IMAGE_THUMB);
         $si->save(AT_PA_CONTENT_DIR . $album_file_path_tn . $photo_file_path);
     } else {
         if ($image_h > AT_PA_IMAGE) {
             $si->resizeToHeight(AT_PA_IMAGE);
开发者ID:genaromendezl,项目名称:ATutor,代码行数:31,代码来源:albums.php

示例10: waterMark

 /**
  * Watermarks an image
  *
  * @param string $source Watermark image path
  * @param string $position Position on image (can be top-left, top right, bottom-right, bottom-left)
  *
  * @return void
  */
 public function waterMark($source, $position = 'bottom-left')
 {
     // Watermark margins:
     $margins = 5;
     // Getting the waterMark image:
     $w = new SimpleImage();
     $w->load($source);
     // Getting the watermark position:
     switch ($position) {
         case 'top-left':
             $startX = $margins;
             $startY = $margins;
             break;
         case 'top-right':
             $startX = $this->getWidth() - $w->getWidth() - $margins;
             $startY = $margins;
             break;
         case 'bottom-right':
             $startX = $this->getWidth() - $w->getWidth() - $margins;
             $startY = $this->getHeight() - $w->getHeight() - $margins;
             break;
             // Bottom left:
         // Bottom left:
         default:
             $startX = $margins;
             $startY = $this->getHeight() - $w->getHeight() - $margins;
             break;
     }
     $newImage = $this->currentImage;
     imagecopy($newImage, $w->currentImage, $startX, $startY, 0, 0, $w->getWidth(), $w->getHeight());
     $this->currentImage = $newImage;
 }
开发者ID:el-cms,项目名称:elabs,代码行数:40,代码来源:SimpleImageComponent.php

示例11: executeAvatar

 public function executeAvatar(HTTPRequest $request)
 {
     ini_set("memory_limit", '256M');
     $this->page->smarty()->assign('avatar', $this->_profilePro->getAvatar());
     if ($request->fileExists('avatar')) {
         $avatar = $request->fileData('avatar');
         if ($avatar['error'] == 0) {
             $simpleImage = new SimpleImage();
             $simpleImage->load($avatar['tmp_name']);
             if (!is_null($simpleImage->image_type)) {
                 $height = $simpleImage->getHeight();
                 $width = $simpleImage->getWidth();
                 if ($height > $width) {
                     $simpleImage->resizeToHeight(150);
                 } else {
                     $simpleImage->resizeToWidth(150);
                 }
                 $filename = time() . '.jpg';
                 $simpleImage->save($_SERVER['DOCUMENT_ROOT'] . $this->_userDir . $filename);
                 if ($this->_profilePro->getAvatar() != ProfilePro::AVATAR_DEFAULT_PRO) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . $this->_profilePro->getAvatar());
                 }
                 $this->_profilePro->setAvatar($this->_userDir . $filename);
                 $this->_profileProManager->save($this->_profilePro);
                 $this->app->user()->setFlash('avatar-updated');
             } else {
                 $this->app->user()->setFlash('avatar-error');
             }
         } else {
             $this->app->user()->setFlash('avatar-error');
         }
         $this->app->httpResponse()->redirect('/profile-pro');
     }
 }
开发者ID:Tipkin-Commons,项目名称:tipkin,代码行数:34,代码来源:ProfileproController.class.php

示例12: while

                // propose a filename
                $exists = TRUE;
                while ($exists) {
                    $filename = uniqid(rand(), true) . "." . $ext;
                    if (file_exists("../user_content/" . $filename)) {
                        $exists = TRUE;
                    } else {
                        $exists = FALSE;
                    }
                }
                move_uploaded_file($_FILES["files"]["tmp_name"][$key], "../user_content/" . $filename);
                // copy the uploaded file to proper directory
                if (file_exists("../user_content/" . $filename)) {
                    $image = new SimpleImage();
                    $image->load('../user_content/' . $filename);
                    if ($image->getWidth() > $image->getHeight()) {
                        $image->resizeToWidth(80);
                    } else {
                        $image->resizeToHeight(80);
                    }
                    $image->save('../user_content/thumbs/' . $filename);
                    $db->query("INSERT INTO photos (listing_id, filename) VALUES ('{$listing_id}','{$filename}')");
                    // insert db association
                }
                //echo "<a href=\"/uploads/articles/{$_POST['article_id']}.{$ext}\" target=\"_blank\">View Word Document</a>"; // is never shown to the user, debug purpose
            }
        }
    }
}
if (isset($_GET['id'])) {
    if (file_exists("../uploads/articles/" . $_GET['id'] . ".doc")) {
开发者ID:andrewgai,项目名称:businessfieds,代码行数:31,代码来源:photoUpload.php

示例13: mkdir

 // php library for image files management.
 include '../SimpleImage.php';
 $DOC_FILE1 = $_FILES['portada']['tmp_name'];
 $DOC_FILE_NAME1 = $_FILES['portada']['name'];
 // code to resample and upload image file.
 if ($DOC_FILE1 != NULL) {
     $photos_download_dir = "../../imgs/galeria/evento_" . $next_slide . "/";
     // create the new directory if it doesn't exist.
     if (!file_exists($photos_download_dir)) {
         mkdir($photos_download_dir, 0777, true);
     }
     // change spaces to underscores in filename
     $photo_name = 'portada.jpg';
     $photo_big = new SimpleImage();
     $photo_big->load($DOC_FILE1);
     if ($photo_big->getWidth() > 2080 || $photo_big->getHeight() > 1388) {
         if ($photo_big->getWidth() > 2080) {
             $photo_big->resizeToWidth(2080);
         }
         if ($photo_big->getHeight() > 1388) {
             $photo_big->resizeToHeight(1388);
         }
     }
     // save the photo into the videogallery directory.
     $photo_big->save($photos_download_dir . $photo_name, $DOC_FILE_TYPE1);
     //END CODE TO RESAMPLE AND UPLOAD PHOTO FILE.
 }
 unlink($DOC_FILE1);
 $insertSQL = "INSERT INTO eventos (id_evento, nombre, descripcion, portada, fecha_ini, fecha_fin) VALUES ('" . $next_slide . "','" . $_POST['nombre'] . "','" . $_POST['descripcion'] . "','" . $photo_name . "','" . $_POST['fecha_ini'] . "','" . $_POST['fecha_fin'] . "')";
 $Result1 = mysql_query($insertSQL, $elencuentro) or die(mysql_error());
 header("Location: index.php");
开发者ID:adelaparra,项目名称:el-encuentro,代码行数:31,代码来源:nuevo_evento.php

示例14: Upload

                    $ad['url'] = "http://" . $ad['url'];
                }
                $db->update($tbl_ad, "url='" . $ad['url'] . "'", "adid=" . $id);
            }
        }
    }
    if ($_FILES['image']['size'] > 0) {
        $upload = new Upload();
        $upload->dir = 'media/boximages/ad/';
        $upload->tag_name = 'image';
        $upload->uploadFile();
        $imgdir = "./media/boximages/ad/";
        include_once './core/simple.image.core.php';
        $image = new SimpleImage();
        $image->load($imgdir . $upload->file_name);
        if ($image->getWidth() > (int) $config->get('ad', 'standard_image_width')) {
            $image->resizeToWidth((int) $config->get('ad', 'standard_image_width'));
        }
        if ($image->getHeight() > (int) $config->get('ad', 'standard_image_height')) {
            $image->resizeToHeight((int) $config->get('ad', 'standard_image_height'));
        }
        unlink($imgdir . $upload->file_name);
        $image->save($imgdir . $upload->file_name);
        if (substr($_POST['newurl'], 0, 7) != "http://") {
            $_POST['newurl'] = "http://" . $_POST['newurl'];
        }
        $db->insert($tbl_ad, array('img', 'url'), array("'" . $upload->file_name . "'", "'" . $_POST['newurl'] . "'"));
    }
}
$allads = $db->selectList($tbl_ad, '*', 1);
$counter = 0;
开发者ID:tech-nik89,项目名称:lpm4,代码行数:31,代码来源:ad.mod.php

示例15: upload

    function upload($userid, $max_byte_size = 2097152)
    {
        global $debug;
        global $config;
        $dir = 'media/avatar/';
        $msg = '';
        // upload button has been pressed
        if (@$_POST['submit'] == 'Upload') {
            // set allowed file types
            $allowed_types = "(jpg|jpeg|gif|bmp|png)";
            // is really a file?
            if (is_uploaded_file($_FILES["file"]["tmp_name"])) {
                // valid extension?
                if (preg_match("/\\." . $allowed_types . "\$/i", $_FILES["file"]["name"])) {
                    // file size okay?
                    if ($_FILES["file"]["size"] <= $max_byte_size) {
                        // width and height okay?
                        $size = getimagesize($_FILES['file']['tmp_name']);
                        $debug->add('img-size', 'height:' . $size[0] . ' width:' . $size[1]);
                        // get user
                        $u = $this->user->getUserByID($userid);
                        $filename = uniqid($u['userid'] . "_") . "_" . $_FILES["file"]["name"];
                        // everything all right, now copy
                        if (!file_exists($dir . $filename)) {
                            if (copy($_FILES["file"]["tmp_name"], $dir . $filename)) {
                                // Resize image if too large
                                $image = new SimpleImage();
                                $image->load($dir . $filename);
                                if ($image->getWidth() > (int) $config->get('core', 'img-width')) {
                                    $image->resizeToWidth((int) $config->get('core', 'img-width'));
                                }
                                if ($image->getHeight() > (int) $config->get('core', 'img-height')) {
                                    $image->resizeToHeight((int) $config->get('core', 'img-height'));
                                }
                                // Save image
                                $this->remove($filename);
                                $image->save($dir . $filename);
                                // upload successfull
                                $msg = $this->lang->get('upload_successfull');
                                // remove old avatar
                                $this->remove($u['avatar']);
                                // update avatar
                                $this->user->setAvatar($userid, $filename);
                            } else {
                                $msg = $this->lang->get('upload_failed');
                            }
                        } else {
                            $msg = $this->lang->get('upload_failed');
                        }
                    } else {
                        $msg = $this->lang->get('upload_too_large');
                    }
                } else {
                    $msg = $this->lang->get('upload_bad_extension');
                }
            } else {
                $msg = $this->lang->get('upload_failed');
            }
        }
        // display the upload-form
        return '
				<p>
					' . $msg . '
				</p>
				
				<form action="" method="post" enctype="multipart/form-data" name="upload">
					
					<input type="file" name="file" />
					<input type="submit" name="submit" value="Upload" />
					
				</form> 
				
				';
    }
开发者ID:tech-nik89,项目名称:lpm4,代码行数:74,代码来源:avatar.core.php


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