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


PHP createThumbnail函数代码示例

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


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

示例1: uploadImage

function uploadImage($inputName, $uploadDir)
{
    $image = $_FILES[$inputName];
    $imagePath = '';
    // if a file is given
    if (trim($image['tmp_name']) != '') {
        // get the image extension
        $ext = substr(strrchr($image['name'], "."), 1);
        // generate a random new file name to avoid name conflict
        $imagePath = md5(rand() * time()) . ".{$ext}";
        // check the image width. if it exceed the maximum
        // width we must resize it
        $size = getimagesize($image['tmp_name']);
        if ($size[0] > MAX_CATEGORY_IMAGE_WIDTH) {
            $imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_CATEGORY_IMAGE_WIDTH);
        } else {
            // move the image to category image directory
            // if fail set $imagePath to empty string
            if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) {
                $imagePath = '';
            }
        }
    }
    return $imagePath;
}
开发者ID:joevanni,项目名称:gallantic-shopping-cart,代码行数:25,代码来源:processCategory.php

示例2: createImages

function createImages($origFile, $id)
{
    global $portfolioFolder;
    list($origWidth, $origHeight, $origType) = getimagesize($origFile);
    ini_set("memory_limit", "128M");
    $origImage = $origType == 2 ? imagecreatefromjpeg($origFile) : imagecreatefrompng($origFile);
    $aspectRatio = $origWidth / $origHeight;
    createThumbnail($origImage, $origWidth, $origHeight, "{$portfolioFolder}/{$id}-small.png");
    createFullImage($origImage, $origWidth, $origHeight, "{$portfolioFolder}/{$id}-large.jpg");
    imagedestroy($origImage);
    logEvent("create-images", $origFile, $id, $aspectRatio);
}
开发者ID:haleystorm,项目名称:paradise,代码行数:12,代码来源:image-processing.php

示例3: uploadProductImage

function uploadProductImage($inputName, $uploadDir)
{
    $image = $_FILES[$inputName];
    $imagePath = '';
    $thumbnailPath = '';
    // if a file is given
    if (trim($image['tmp_name']) != '') {
        $ext = substr(strrchr($image['name'], "."), 1);
        //$extensions[$image['type']];
        // generate a random new file name to avoid name conflict
        $imagePath = md5(rand() * time()) . ".{$ext}";
        list($width, $height, $type, $attr) = getimagesize($image['tmp_name']);
        // make sure the image width does not exceed the
        // maximum allowed width
        if (LIMIT_PRODUCT_WIDTH && $width > MAX_PRODUCT_IMAGE_WIDTH) {
            $result = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_PRODUCT_IMAGE_WIDTH);
            $imagePath = $result;
        } else {
            $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
        }
        if ($result) {
            // create thumbnail
            $thumbnailPath = md5(rand() * time()) . ".{$ext}";
            $result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
            // create thumbnail failed, delete the image
            if (!$result) {
                unlink($uploadDir . $imagePath);
                $imagePath = $thumbnailPath = '';
            } else {
                $thumbnailPath = $result;
            }
        } else {
            // the product cannot be upload / resized
            $imagePath = $thumbnailPath = '';
        }
    }
    return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
}
开发者ID:joevanni,项目名称:gallantic-shopping-cart,代码行数:38,代码来源:processProduct.php

示例4: loadAttachmentContext

function loadAttachmentContext($ID_MSG)
{
    global $attachments, $modSettings, $txt, $scripturl, $topic, $db_prefix, $sourcedir;
    // Set up the attachment info - based on code by Meriadoc.
    $attachmentData = array();
    if (isset($attachments[$ID_MSG]) && !empty($modSettings['attachmentEnable'])) {
        foreach ($attachments[$ID_MSG] as $i => $attachment) {
            $attachmentData[$i] = array('id' => $attachment['ID_ATTACH'], 'name' => htmlspecialchars($attachment['filename']), 'downloads' => $attachment['downloads'], 'size' => round($attachment['filesize'] / 1024, 2) . ' ' . $txt['smf211'], 'byte_size' => $attachment['filesize'], 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['ID_ATTACH'], 'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['ID_ATTACH'] . '">' . htmlspecialchars($attachment['filename']) . '</a>', 'is_image' => !empty($attachment['width']) && !empty($attachment['height']) && !empty($modSettings['attachmentShowImages']));
            if (!$attachmentData[$i]['is_image']) {
                continue;
            }
            $attachmentData[$i]['real_width'] = $attachment['width'];
            $attachmentData[$i]['width'] = $attachment['width'];
            $attachmentData[$i]['real_height'] = $attachment['height'];
            $attachmentData[$i]['height'] = $attachment['height'];
            // Let's see, do we want thumbs?
            if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachment['width'] > $modSettings['attachmentThumbWidth'] || $attachment['height'] > $modSettings['attachmentThumbHeight']) && strlen($attachment['filename']) < 249) {
                // A proper thumb doesn't exist yet? Create one!
                if (empty($attachment['ID_THUMB']) || $attachment['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attachment['thumb_height'] > $modSettings['attachmentThumbHeight'] || $attachment['thumb_width'] < $modSettings['attachmentThumbWidth'] && $attachment['thumb_height'] < $modSettings['attachmentThumbHeight']) {
                    $filename = getAttachmentFilename($attachment['filename'], $attachment['ID_ATTACH']);
                    require_once $sourcedir . '/Subs-Graphics.php';
                    if (createThumbnail($filename, $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight'])) {
                        // Calculate the size of the created thumbnail.
                        list($attachment['thumb_width'], $attachment['thumb_height']) = @getimagesize($filename . '_thumb');
                        $thumb_size = filesize($filename . '_thumb');
                        $thumb_filename = addslashes($attachment['filename'] . '_thumb');
                        // Add this beauty to the database.
                        db_query("\n\t\t\t\t\t\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t\t\t\t\t\t(ID_MSG, attachmentType, filename, size, width, height)\n\t\t\t\t\t\t\tVALUES ({$ID_MSG}, 3, '{$thumb_filename}', " . (int) $thumb_size . ", " . (int) $attachment['thumb_width'] . ", " . (int) $attachment['thumb_height'] . ")", __FILE__, __LINE__);
                        $attachment['ID_THUMB'] = db_insert_id();
                        if (!empty($attachment['ID_THUMB'])) {
                            db_query("\n\t\t\t\t\t\t\t\tUPDATE {$db_prefix}attachments\n\t\t\t\t\t\t\t\tSET ID_THUMB = {$attachment['ID_THUMB']}\n\t\t\t\t\t\t\t\tWHERE ID_ATTACH = {$attachment['ID_ATTACH']}\n\t\t\t\t\t\t\t\tLIMIT 1", __FILE__, __LINE__);
                            $thumb_realname = getAttachmentFilename($thumb_filename, $attachment['ID_THUMB'], true);
                            rename($filename . '_thumb', $modSettings['attachmentUploadDir'] . '/' . $thumb_realname);
                        }
                    }
                }
                $attachmentData[$i]['width'] = $attachment['thumb_width'];
                $attachmentData[$i]['height'] = $attachment['thumb_height'];
            }
            if (!empty($attachment['ID_THUMB'])) {
                $attachmentData[$i]['thumbnail'] = array('id' => $attachment['ID_THUMB'], 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['ID_THUMB'] . ';image');
            }
            $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['ID_THUMB']);
            // If thumbnails are disabled, check the maximum size of the image.
            if (!$attachmentData[$i]['thumbnail']['has_thumb'] && (!empty($modSettings['max_image_width']) && $attachment['width'] > $modSettings['max_image_width'] || !empty($modSettings['max_image_height']) && $attachment['height'] > $modSettings['max_image_height'])) {
                if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $attachment['height'] * $modSettings['max_image_width'] / $attachment['width'] <= $modSettings['max_image_height'])) {
                    $attachmentData[$i]['width'] = $modSettings['max_image_width'];
                    $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
                } elseif (!empty($modSettings['max_image_width'])) {
                    $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
                    $attachmentData[$i]['height'] = $modSettings['max_image_height'];
                }
            } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) {
                // If the image is too large to show inline, make it a popup.
                if (!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width'] || !empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']) {
                    $attachmentData[$i]['thumbnail']['javascript'] = "return reqWin('" . $attachmentData[$i]['href'] . ";image', " . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
                } else {
                    $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['ID_ATTACH'] . ');';
                }
            }
            if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
                $attachmentData[$i]['downloads']++;
            }
        }
    }
    return $attachmentData;
}
开发者ID:alencarmo,项目名称:OCF,代码行数:67,代码来源:Display.php

示例5: employees_update

function employees_update($selected_id)
{
    global $Translation;
    if ($_GET['update_x'] != '') {
        $_POST = $_GET;
    }
    // mm: can member edit record?
    $arrPerm = getTablePermissions('employees');
    $ownerGroupID = sqlValue("select groupID from membership_userrecords where tableName='employees' and pkValue='" . makeSafe($selected_id) . "'");
    $ownerMemberID = sqlValue("select lcase(memberID) from membership_userrecords where tableName='employees' and pkValue='" . makeSafe($selected_id) . "'");
    if ($arrPerm[3] == 1 && $ownerMemberID == getLoggedMemberID() || $arrPerm[3] == 2 && $ownerGroupID == getLoggedGroupID() || $arrPerm[3] == 3) {
        // allow update?
        // update allowed, so continue ...
    } else {
        return false;
    }
    $data['TitleOfCourtesy'] = makeSafe($_POST['TitleOfCourtesy']);
    if ($data['TitleOfCourtesy'] == empty_lookup_value) {
        $data['TitleOfCourtesy'] = '';
    }
    $data['LastName'] = makeSafe($_POST['LastName']);
    if ($data['LastName'] == empty_lookup_value) {
        $data['LastName'] = '';
    }
    $data['FirstName'] = makeSafe($_POST['FirstName']);
    if ($data['FirstName'] == empty_lookup_value) {
        $data['FirstName'] = '';
    }
    $data['Title'] = makeSafe($_POST['Title']);
    if ($data['Title'] == empty_lookup_value) {
        $data['Title'] = '';
    }
    $data['BirthDate'] = intval($_POST['BirthDateYear']) . '-' . intval($_POST['BirthDateMonth']) . '-' . intval($_POST['BirthDateDay']);
    $data['BirthDate'] = parseMySQLDate($data['BirthDate'], '');
    $data['HireDate'] = intval($_POST['HireDateYear']) . '-' . intval($_POST['HireDateMonth']) . '-' . intval($_POST['HireDateDay']);
    $data['HireDate'] = parseMySQLDate($data['HireDate'], '1');
    $data['Address'] = br2nl(makeSafe($_POST['Address']));
    $data['City'] = makeSafe($_POST['City']);
    if ($data['City'] == empty_lookup_value) {
        $data['City'] = '';
    }
    $data['Region'] = makeSafe($_POST['Region']);
    if ($data['Region'] == empty_lookup_value) {
        $data['Region'] = '';
    }
    $data['PostalCode'] = makeSafe($_POST['PostalCode']);
    if ($data['PostalCode'] == empty_lookup_value) {
        $data['PostalCode'] = '';
    }
    $data['Country'] = makeSafe($_POST['Country']);
    if ($data['Country'] == empty_lookup_value) {
        $data['Country'] = '';
    }
    $data['HomePhone'] = makeSafe($_POST['HomePhone']);
    if ($data['HomePhone'] == empty_lookup_value) {
        $data['HomePhone'] = '';
    }
    $data['Extension'] = makeSafe($_POST['Extension']);
    if ($data['Extension'] == empty_lookup_value) {
        $data['Extension'] = '';
    }
    $data['Notes'] = makeSafe($_POST['Notes']);
    if ($data['Notes'] == empty_lookup_value) {
        $data['Notes'] = '';
    }
    $data['ReportsTo'] = makeSafe($_POST['ReportsTo']);
    if ($data['ReportsTo'] == empty_lookup_value) {
        $data['ReportsTo'] = '';
    }
    $data['selectedID'] = makeSafe($selected_id);
    if ($_POST['Photo_remove'] == 1) {
        $data['Photo'] = '';
        // delete file from server
        $res = sql("select `Photo` from `employees` where `EmployeeID`='" . makeSafe($selected_id) . "'", $eo);
        if ($row = @db_fetch_row($res)) {
            if ($row[0] != '') {
                @unlink(getUploadDir('') . $row[0]);
                preg_match('/^[a-z0-9_]+\\.(gif|png|jpg|jpeg|jpe)$/i', $row[0], $m);
                $thumbDV = str_replace(".{$m['1']}ffffgggg", "_dv.{$m['1']}", $row[0] . 'ffffgggg');
                $thumbTV = str_replace(".{$m['1']}ffffgggg", "_tv.{$m['1']}", $row[0] . 'ffffgggg');
                @unlink(getUploadDir('') . $thumbTV);
                @unlink(getUploadDir('') . $thumbDV);
            }
        }
    } else {
        $data['Photo'] = PrepareUploadedFile('Photo', 153600, 'jpg|jpeg|gif|png', false, "");
        if ($data['Photo']) {
            createThumbnail($data['Photo'], getThumbnailSpecs('employees', 'Photo', 'tv'));
        }
        // delete file from server
        if ($data['Photo'] != '') {
            $res = sql("select `Photo` from `employees` where `EmployeeID`='" . makeSafe($selected_id) . "'", $eo);
            if ($row = @db_fetch_row($res)) {
                if ($row[0] != '') {
                    @unlink(getUploadDir('') . $row[0]);
                    preg_match('/^[a-z0-9_]+\\.(gif|png|jpg|jpeg|jpe)$/i', $row[0], $m);
                    $thumbDV = str_replace(".{$m['1']}ffffgggg", "_dv.{$m['1']}", $row[0] . 'ffffgggg');
                    $thumbTV = str_replace(".{$m['1']}ffffgggg", "_tv.{$m['1']}", $row[0] . 'ffffgggg');
                    @unlink(getUploadDir('') . $thumbTV);
                    @unlink(getUploadDir('') . $thumbDV);
//.........这里部分代码省略.........
开发者ID:ahmedandroid1980,项目名称:appgini,代码行数:101,代码来源:employees_dml.php

示例6: explode

 $i = 1;
 $pieces = explode('.', $name);
 $filename = $pieces[0];
 if (in_array($extension, $allowed)) {
     if ($file_error === 0) {
         $file_dir = "images/" . $filename . "." . $pieces[1];
         while (file_exists("../images/" . $filename . "." . $pieces[1])) {
             $filename = $name_ext["filename"] . "_" . $i++;
             //$filename = $pieces[0] . "_" . $i++;
         }
         $file_dir = "images/" . $filename . "." . $pieces[1];
         $uploaded[$position] = $file_dir;
         if (move_uploaded_file($file_tmp, "../" . $file_dir)) {
             $metaSystem = new Metaclass($file_dir);
             $currentMeta = $metaSystem->getMeta();
             createThumbnail($filename . "." . $pieces[1]);
             $uploaded[$position] = $file_dir;
         } else {
             $failed[$position] = "[{$filename}] failed to upload.";
         }
     } else {
         $failed[$position] = "[{$filename}] errored with code {$file_error}.";
     }
 } else {
     $failed[$position] = "[{$filename}] file extension '{$extension}' is not allowed.";
 }
 if (!empty($uploaded)) {
     echo "{$filename} has been successfully uploaded!.";
     echo $filename;
     $picture->addPicture($filename, $extension, $file_dir);
     // set proper permissions on the new file
开发者ID:OmniPics,项目名称:OmniPics,代码行数:31,代码来源:bulkUpload.php

示例7: loadAttachmentContext

function loadAttachmentContext($id_msg)
{
    global $attachments, $modSettings, $txt, $scripturl, $topic, $sourcedir, $smcFunc;
    // Set up the attachment info - based on code by Meriadoc.
    $attachmentData = array();
    $have_unapproved = false;
    if (isset($attachments[$id_msg]) && !empty($modSettings['attachmentEnable'])) {
        foreach ($attachments[$id_msg] as $i => $attachment) {
            $attachmentData[$i] = array('id' => $attachment['id_attach'], 'name' => preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($attachment['filename'])), 'downloads' => $attachment['downloads'], 'size' => round($attachment['filesize'] / 1024, 2) . ' ' . $txt['kilobyte'], 'byte_size' => $attachment['filesize'], 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_attach'], 'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_attach'] . '">' . htmlspecialchars($attachment['filename']) . '</a>', 'is_image' => !empty($attachment['width']) && !empty($attachment['height']) && !empty($modSettings['attachmentShowImages']), 'is_approved' => $attachment['approved']);
            // If something is unapproved we'll note it so we can sort them.
            if (!$attachment['approved']) {
                $have_unapproved = true;
            }
            if (!$attachmentData[$i]['is_image']) {
                continue;
            }
            $attachmentData[$i]['real_width'] = $attachment['width'];
            $attachmentData[$i]['width'] = $attachment['width'];
            $attachmentData[$i]['real_height'] = $attachment['height'];
            $attachmentData[$i]['height'] = $attachment['height'];
            // Let's see, do we want thumbs?
            if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachment['width'] > $modSettings['attachmentThumbWidth'] || $attachment['height'] > $modSettings['attachmentThumbHeight']) && strlen($attachment['filename']) < 249) {
                // A proper thumb doesn't exist yet? Create one!
                if (empty($attachment['id_thumb']) || $attachment['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attachment['thumb_height'] > $modSettings['attachmentThumbHeight'] || $attachment['thumb_width'] < $modSettings['attachmentThumbWidth'] && $attachment['thumb_height'] < $modSettings['attachmentThumbHeight']) {
                    $filename = getAttachmentFilename($attachment['filename'], $attachment['id_attach'], $attachment['id_folder']);
                    require_once $sourcedir . '/Subs-Graphics.php';
                    if (createThumbnail($filename, $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight'])) {
                        // So what folder are we putting this image in?
                        if (!empty($modSettings['currentAttachmentUploadDir'])) {
                            if (!is_array($modSettings['attachmentUploadDir'])) {
                                $modSettings['attachmentUploadDir'] = @unserialize($modSettings['attachmentUploadDir']);
                            }
                            $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
                            $id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
                        } else {
                            $path = $modSettings['attachmentUploadDir'];
                            $id_folder_thumb = 1;
                        }
                        // Calculate the size of the created thumbnail.
                        $size = @getimagesize($filename . '_thumb');
                        list($attachment['thumb_width'], $attachment['thumb_height']) = $size;
                        $thumb_size = filesize($filename . '_thumb');
                        // These are the only valid image types for SMF.
                        $validImageTypes = array(1 => 'gif', 2 => 'jpeg', 3 => 'png', 5 => 'psd', 6 => 'bmp', 7 => 'tiff', 8 => 'tiff', 9 => 'jpeg', 14 => 'iff');
                        // What about the extension?
                        $thumb_ext = isset($validImageTypes[$size[2]]) ? $validImageTypes[$size[2]] : '';
                        // Figure out the mime type.
                        if (!empty($size['mime'])) {
                            $thumb_mime = $size['mime'];
                        } else {
                            $thumb_mime = 'image/' . $thumb_ext;
                        }
                        $thumb_filename = $attachment['filename'] . '_thumb';
                        $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
                        // Add this beauty to the database.
                        $smcFunc['db_insert']('', '{db_prefix}attachments', array('id_folder' => 'int', 'id_msg' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'size' => 'int', 'width' => 'int', 'height' => 'int', 'fileext' => 'string', 'mime_type' => 'string'), array($id_folder_thumb, $id_msg, 3, $thumb_filename, $thumb_hash, (int) $thumb_size, (int) $attachment['thumb_width'], (int) $attachment['thumb_height'], $thumb_ext, $thumb_mime), array('id_attach'));
                        $old_id_thumb = $attachment['id_thumb'];
                        $attachment['id_thumb'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
                        if (!empty($attachment['id_thumb'])) {
                            $smcFunc['db_query']('', '
								UPDATE {db_prefix}attachments
								SET id_thumb = {int:id_thumb}
								WHERE id_attach = {int:id_attach}', array('id_thumb' => $attachment['id_thumb'], 'id_attach' => $attachment['id_attach']));
                            $thumb_realname = getAttachmentFilename($thumb_filename, $attachment['id_thumb'], $id_folder_thumb, false, $thumb_hash);
                            rename($filename . '_thumb', $thumb_realname);
                            // Do we need to remove an old thumbnail?
                            if (!empty($old_id_thumb)) {
                                require_once $sourcedir . '/ManageAttachments.php';
                                removeAttachments(array('id_attach' => $old_id_thumb), '', false, false);
                            }
                        }
                    }
                }
                // Only adjust dimensions on successful thumbnail creation.
                if (!empty($attachment['thumb_width']) && !empty($attachment['thumb_height'])) {
                    $attachmentData[$i]['width'] = $attachment['thumb_width'];
                    $attachmentData[$i]['height'] = $attachment['thumb_height'];
                }
            }
            if (!empty($attachment['id_thumb'])) {
                $attachmentData[$i]['thumbnail'] = array('id' => $attachment['id_thumb'], 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_thumb'] . ';image');
            }
            $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
            // If thumbnails are disabled, check the maximum size of the image.
            if (!$attachmentData[$i]['thumbnail']['has_thumb'] && (!empty($modSettings['max_image_width']) && $attachment['width'] > $modSettings['max_image_width'] || !empty($modSettings['max_image_height']) && $attachment['height'] > $modSettings['max_image_height'])) {
                if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $attachment['height'] * $modSettings['max_image_width'] / $attachment['width'] <= $modSettings['max_image_height'])) {
                    $attachmentData[$i]['width'] = $modSettings['max_image_width'];
                    $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
                } elseif (!empty($modSettings['max_image_width'])) {
                    $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
                    $attachmentData[$i]['height'] = $modSettings['max_image_height'];
                }
            } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) {
                // If the image is too large to show inline, make it a popup.
                if (!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width'] || !empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']) {
                    $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
                } else {
                    $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
                }
            }
//.........这里部分代码省略.........
开发者ID:sk8rdude461,项目名称:moparscape.org-smf,代码行数:101,代码来源:Display.php

示例8: strtolower

}
// upload file
if ($allowuploads && $_FILES['file']) {
    $upload = true;
    if (!$overwrite) {
        if (file_exists($leadon . $_FILES['file']['name'])) {
            $upload = false;
        }
    }
    $ext = strtolower(substr($_FILES['file']['name'], strrpos($_FILES['file']['name'], '.') + 1));
    if (!in_array($ext, $supportedextentions)) {
        $upload = false;
    }
    if ($upload) {
        move_uploaded_file($_FILES['file']['tmp_name'], $leadon . $_FILES['file']['name']);
        createThumbnail($leadon, $_FILES['file']['name'], $thumbs_directory, '120');
    }
}
if ($allowuploads) {
    $phpallowuploads = (bool) ini_get('file_uploads');
    $phpmaxsize = ini_get('upload_max_filesize');
    $phpmaxsize = trim($phpmaxsize);
    $last = strtolower($phpmaxsize[strlen($phpmaxsize) - 1]);
    switch ($last) {
        case 'g':
            $phpmaxsize *= 1024;
        case 'm':
            $phpmaxsize *= 1024;
    }
}
?>
开发者ID:rcheru,项目名称:vk.rche.ru,代码行数:31,代码来源:insert_image.php

示例9: createAttachment


//.........这里部分代码省略.........
    if (empty($attachmentOptions['file_hash'])) {
        $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, true);
    }
    // Is the file too big?
    if (!empty($modSettings['attachmentSizeLimit']) && $attachmentOptions['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
        $attachmentOptions['errors'][] = 'too_large';
    }
    if (!empty($modSettings['attachmentCheckExtensions'])) {
        $allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
        foreach ($allowed as $k => $dummy) {
            $allowed[$k] = trim($dummy);
        }
        if (!in_array(strtolower(substr(strrchr($attachmentOptions['name'], '.'), 1)), $allowed)) {
            $attachmentOptions['errors'][] = 'bad_extension';
        }
    }
    if (!empty($modSettings['attachmentDirSizeLimit'])) {
        // Make sure the directory isn't full.
        $dirSize = 0;
        $dir = @opendir($modSettings['attachmentUploadDir']) or fatal_lang_error('smf115b');
        while ($file = readdir($dir)) {
            if (substr($file, 0, -1) == '.') {
                continue;
            }
            if (preg_match('~^post_tmp_\\d+_\\d+$~', $file) != 0) {
                // Temp file is more than 5 hours old!
                if (filemtime($modSettings['attachmentUploadDir'] . '/' . $file) < time() - 18000) {
                    @unlink($modSettings['attachmentUploadDir'] . '/' . $file);
                }
                continue;
            }
            $dirSize += filesize($modSettings['attachmentUploadDir'] . '/' . $file);
        }
        closedir($dir);
        // Too big!  Maybe you could zip it or something...
        if ($attachmentOptions['size'] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024) {
            $attachmentOptions['errors'][] = 'directory_full';
        }
    }
    // Check if the file already exists.... (for those who do not encrypt their filenames...)
    if (empty($modSettings['attachmentEncryptFilenames'])) {
        // Make sure they aren't trying to upload a nasty file.
        $disabledFiles = array('con', 'com1', 'com2', 'com3', 'com4', 'prn', 'aux', 'lpt1', '.htaccess', 'index.php');
        if (in_array(strtolower(basename($attachmentOptions['name'])), $disabledFiles)) {
            $attachmentOptions['errors'][] = 'bad_filename';
        }
        // Check if there's another file with that name...
        $request = db_query("\n\t\t\tSELECT ID_ATTACH\n\t\t\tFROM {$db_prefix}attachments\n\t\t\tWHERE filename = '" . strtolower($attachmentOptions['name']) . "'\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        if (mysql_num_rows($request) > 0) {
            $attachmentOptions['errors'][] = 'taken_filename';
        }
        mysql_free_result($request);
    }
    if (!empty($attachmentOptions['errors'])) {
        return false;
    }
    if (!is_writable($modSettings['attachmentUploadDir'])) {
        fatal_lang_error('attachments_no_write');
    }
    db_query("\n\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t(ID_MSG, filename, file_hash, size, width, height)\n\t\tVALUES (" . (int) $attachmentOptions['post'] . ", SUBSTRING('" . $attachmentOptions['name'] . "', 1, 255), '{$attachmentOptions['file_hash']}', " . (int) $attachmentOptions['size'] . ', ' . (empty($attachmentOptions['width']) ? '0' : (int) $attachmentOptions['width']) . ', ' . (empty($attachmentOptions['height']) ? '0' : (int) $attachmentOptions['height']) . ')', __FILE__, __LINE__);
    $attachmentOptions['id'] = db_insert_id();
    if (empty($attachmentOptions['id'])) {
        return false;
    }
    $attachmentOptions['destination'] = getAttachmentFilename(basename($attachmentOptions['name']), $attachmentOptions['id'], false, $attachmentOptions['file_hash']);
    if ($already_uploaded) {
        rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
    } elseif (!move_uploaded_file($attachmentOptions['tmp_name'], $attachmentOptions['destination'])) {
        fatal_lang_error('smf124');
    } elseif ($file_restricted) {
        list($attachmentOptions['width'], $attachmentOptions['height']) = @getimagesize($attachmentOptions['destination']);
        if (!empty($attachmentOptions['width']) && !empty($attachmentOptions['height'])) {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}attachments\n\t\t\t\tSET\n\t\t\t\t\twidth = " . (int) $attachmentOptions['width'] . ",\n\t\t\t\t\theight = " . (int) $attachmentOptions['height'] . "\n\t\t\t\tWHERE ID_ATTACH = {$attachmentOptions['id']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
    }
    // Attempt to chmod it.
    @chmod($attachmentOptions['destination'], 0644);
    if (!empty($attachmentOptions['skip_thumbnail']) || empty($attachmentOptions['width']) && empty($attachmentOptions['height'])) {
        return true;
    }
    // Like thumbnails, do we?
    if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) {
        require_once $sourcedir . '/Subs-Graphics.php';
        if (createThumbnail($attachmentOptions['destination'], $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight'])) {
            // Figure out how big we actually made it.
            list($thumb_width, $thumb_height) = @getimagesize($attachmentOptions['destination'] . '_thumb');
            $thumb_filename = addslashes($attachmentOptions['name'] . '_thumb');
            $thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
            // To the database we go!
            $thumb_file_hash = getAttachmentFilename($thumb_filename, false, true);
            db_query("\n\t\t\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t\t\t(ID_MSG, attachmentType, filename, file_hash, size, width, height)\n\t\t\t\tVALUES (" . (int) $attachmentOptions['post'] . ", 3, SUBSTRING('{$thumb_filename}', 1, 255), '{$thumb_file_hash}', " . (int) $thumb_size . ", " . (int) $thumb_width . ", " . (int) $thumb_height . ")", __FILE__, __LINE__);
            $attachmentOptions['thumb'] = db_insert_id();
            if (!empty($attachmentOptions['thumb'])) {
                db_query("\n\t\t\t\t\tUPDATE {$db_prefix}attachments\n\t\t\t\t\tSET ID_THUMB = {$attachmentOptions['thumb']}\n\t\t\t\t\tWHERE ID_ATTACH = {$attachmentOptions['id']}\n\t\t\t\t\tLIMIT 1", __FILE__, __LINE__);
                rename($attachmentOptions['destination'] . '_thumb', getAttachmentFilename($thumb_filename, $attachmentOptions['thumb'], false, $thumb_file_hash));
            }
        }
    }
    return true;
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:101,代码来源:Subs-Post.php

示例10: getImage

    getImage();
}
if (!preg_match('/^[a-z0-9_]+\\.(gif|png|jpg|jpeg|jpe)$/i', $i, $m)) {
    getImage();
}
if ($v != 'tv' && $v != 'dv') {
    getImage();
}
$img = $p[$t][$f] . $i;
$thumb = str_replace(".{$m['1']}ffffgggg", "_{$v}.{$m['1']}", $img . 'ffffgggg');
// if thumbnail exists and the user is not admin, output it without rebuilding the thumbnail
if (getImage($thumb) && !getLoggedAdmin()) {
    exit;
}
// otherwise, try to create the thumbnail and output it
if (!createThumbnail($img, getThumbnailSpecs($t, $f, $v))) {
    getImage();
}
if (!getImage($thumb)) {
    getImage();
}
function getImage($img = '')
{
    if (!$img) {
        // default image to return
        $img = './photo.gif';
        $exit = TRUE;
    }
    $thumbInfo = @getimagesize($img);
    $fp = @fopen($img, 'rb');
    if ($thumbInfo && $fp) {
开发者ID:bigprof,项目名称:Symptoms-and-diseases-database,代码行数:31,代码来源:thumbnail.php

示例11: move_uploaded_file

    $src = $filename;
    $tn_src = $filename;
    // Validates the form input
    //if(strlen($_POST['description']) < 4)
    //$error['description'] = '<p class="alert">Please enter a description for your photo. </p>';
    if ($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) {
        $error['no_file'] = '<p class="alert">กรุณาเลือกรูปภาพเพื่ออัพโหลด! </p>';
    }
    if (!$error) {
        move_uploaded_file($source, $target);
        $q = "INSERT into gs_photo(description, src, tn_src ,album_id) VALUES('{$description}', '{$src}', '{$tn_src}', '{$id}')";
        $result = $mysqli->query($q) or die(mysqli_error($mysqli));
        if ($result) {
            //echo "Success! Your file has been uploaded";
        }
        createThumbnail($filename);
        header("location: index.php?album_id=" . $id);
    }
    // end preg_match
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" href="css/default.css" />
	<title>My Photos</title>
	<script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script>
	<script type="text/javascript">
	$(function() {
开发者ID:ultr4h4ck,项目名称:project_gspa,代码行数:31,代码来源:index.php

示例12: uniqid

             //一意のファイルネーム
             $uqFileName = uniqid('p') . '.' . getExt($fileName);
             $tmpName = $_FILES['addPhoto']['tmp_name'][$key];
             if (is_uploaded_file($tmpName)) {
                 if (move_uploaded_file($tmpName, "photo/" . $uqFileName)) {
                     chmod("photo/" . $uqFileName, 0644);
                     //                $stmt = $pdo->prepare("INSERT INTO photo (p_id, p_fileName, p_date, p_resistDate, p_title, p_koujiName, p_koujiShu,p_class,p_subClass,p_koushuYobi,p_place,p_period,p_infoYobi,p_photographer,p_company,p_description,p_floor,p_xStreet,p_yStreet,p_starFlg,p_blackBoardFlg)VALUES(NULL, :p_fileName, sysdate(), sysdate(), NULL , NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,:p_photographer,NULL ,NULL ,NULL ,NULL ,NULL ,0,0)");
                     $stmt = $pdo->prepare("INSERT INTO photo (p_id, p_fileName, p_date ,p_resistDate,p_photographer,p_starFlg,p_blackBoardFlg )VALUES(NULL, :p_fileName, sysdate(), sysdate(),:p_photographer,0,0)");
                     $stmt->bindValue(':p_fileName', $uqFileName);
                     $stmt->bindValue(':p_photographer', '中島貴春');
                     $status = $stmt->execute();
                     if ($status == false) {
                         echo "SQLエラー";
                         exit;
                     }
                     createThumbnail($uqFileName);
                 }
             }
         }
     }
     header("Location:main.php");
     //------------------------写真削除------------------------
 } else {
     if ($_POST["post_flg"] == 2) {
         if (isset($_POST['selectedNo'])) {
             $queryStr = 'DELETE FROM photo WHERE p_id IN(';
             //クエリ分に選択されたIDを足していく
             foreach ($_POST['selectedNo'] as $val) {
                 $queryStr .= $val . ',';
             }
             //最後にいらない,を削除
开发者ID:palpal1988,项目名称:mentor,代码行数:31,代码来源:main.php

示例13: filter_var

$filename = filter_var($title . generateRandomString(5) . "." . $nameExif, FILTER_SANITIZE_SPECIAL_CHARS);
// Make sure description, set or not, is properly set
$desc = '';
if ($_POST['imageDesc']) {
    $desc = filter_var($_POST['imageDesc'], FILTER_SANITIZE_SPECIAL_CHARS);
    if ($_POST['imageDesc'] == 'undefined') {
        $desc = '';
    }
}
// Make the user's folder if it's their first upload.
if (!is_dir($upload_dir)) {
    mkdir($upload_dir, '0755', true);
}
// Save the image to disk in folder with user's id
if (move_uploaded_file($_FILES['uploadfile']["tmp_name"], $upload_dir . $filename)) {
    $tempVar = createThumbnail(file_get_contents($upload_dir . $filename));
    if ($tempVar) {
        $stm->bindParam(":thumbnail", $tempVar, PDO::PARAM_LOB);
        $stm->bindParam(":userID", $_SESSION['userID'], PDO::PARAM_STR);
        $stm->bindParam(":imageTitle", $title, PDO::PARAM_STR);
        $stm->bindParam(":imageName", $filename, PDO::PARAM_STR);
        $stm->bindParam(":imageDesc", $desc, PDO::PARAM_STR);
        $stm->bindParam(":inFolderID", $_POST['folderID'], PDO::PARAM_INT);
        if (!$stm->execute()) {
            die("Failed: Unable to upload image to database.");
        } else {
            $lastID = $db->lastInsertId();
            // Add tags
            if ($_POST['tags'] != '') {
                $tags = explode(',', $_POST['tags']);
                foreach ($tags as $tag) {
开发者ID:LarsWalter,项目名称:arcadian-giggle,代码行数:31,代码来源:uploadImage.php

示例14: uploadFiles1

 public function uploadFiles1($conn, $files, $kde)
 {
     $fileCount = count($files["name"]);
     if ($fileCount + count($this->attachments) > 100) {
         echoError("err-too-many-attachments");
         return;
     }
     for ($i = 0; $i < $fileCount; $i++) {
         $subor = $files["name"][$i];
         $ext = pathinfo($subor, PATHINFO_EXTENSION);
         if (checkUploadFile($ext, $files["size"][$i])) {
             $typ = "program";
             if (isSupportedImageFormat($ext)) {
                 $typ = "image";
             }
             if (mysqli_query($conn, "INSERT INTO " . $typ . "s (context_id, original_name) VALUES (" . $this->id . ",\"" . $subor . "\")")) {
                 $new_name = mysqli_insert_id($conn) . "." . $ext;
                 if ($typ == "image") {
                     $target_file = $kde . $typ . "s/big/" . $new_name;
                     $target_file2 = $kde . $typ . "s/small/" . $new_name;
                     if (!file_exists($kde . $typ . "s/big")) {
                         mkdir($kde . $typ . "s/big", 0777, true);
                     }
                     if (!file_exists($kde . $typ . "s/small")) {
                         mkdir($kde . $typ . "s/small", 0777, true);
                     }
                 } else {
                     $target_file = $kde . $typ . "s/" . $new_name;
                     if (!file_exists($kde . $typ . "s")) {
                         mkdir($kde . $typ . "s", 0777, true);
                     }
                 }
                 if (move_uploaded_file($files["tmp_name"][$i], $target_file)) {
                     if ($typ == "image") {
                         createThumbnail($new_name, 250, 250, $kde . $typ . "s/big", $kde . $typ . "s/small/");
                     }
                     echoMessage("m-file-uploaded", $subor);
                 } else {
                     mysqli_query($conn, "DELETE FROM " . $typ . "s WHERE " . $typ . "_id = " . mysqli_insert_id($conn));
                     echoError("err-file-upload", $subor);
                 }
             } else {
                 echoError("err-file-upload-db", $subor . ": " . mysqli_error($conn));
             }
         } else {
             echoError("err-file-too-big", $subor);
         }
     }
 }
开发者ID:Chaos-TIS,项目名称:letna-liga,代码行数:49,代码来源:Context.php

示例15: createNewHomePageImage

 public function createNewHomePageImage($img_name, $href, $caption, $size)
 {
     if (isset($_FILES[$img_name])) {
         $target_dir = "/uploads/news/";
         switch ($_FILES[$img_name]["type"]) {
             case "image/gif":
                 $file_ext = ".gif";
                 break;
             case "image/jpeg":
                 $file_ext = ".jpeg";
                 break;
             case "image/jpg":
                 $file_ext = ".jpg";
                 break;
             case "image/pjpeg":
                 $file_ext = ".jpeg";
                 break;
             case "image/png":
                 $file_ext = ".png";
                 break;
             default:
                 $file_ext = "";
                 break;
         }
         if (empty($file_ext)) {
             throw new Exception("Unknown file format");
         }
         $img_url = $target_dir . uniqid("img_") . $file_ext;
         $target_file = ROOT . $img_url;
     } else {
         throw new Exception("No image set");
     }
     $link = AdminUtility::getDefaultDBConnection();
     //Check if exists
     $check_query = "select * from home_page_images where img_url='" . mysqli_escape_string($link, $img_url) . "' " . "and caption = '" . mysqli_escape_string($link, $caption) . "'";
     $check_result = mysqli_query($link, $check_query);
     if (!$check_result) {
         //Log error
         AdminUtility::logMySQLError($link);
         throw new Exception("Oops! Something went wrong");
     } elseif (mysqli_num_rows($check_result) > 0) {
         throw new Exception("Image already exists");
     }
     //Validate news
     if (empty($href) || empty($caption)) {
         throw new Exception("Link or caption is empty");
     }
     //upload
     if (isset($_FILES[$img_name])) {
         if (!move_uploaded_file($_FILES[$img_name]["tmp_name"], $target_file)) {
             throw new Exception("Upload failed");
         }
     } else {
         throw new Exception("Upload empty");
     }
     //Check image dimension
     try {
         checkDimension($target_file, $size);
     } catch (Exception $exc) {
         unlink($target_file);
         throw new Exception($exc->getMessage());
     }
     //Create thumbnail
     $thumb_url = createThumbnail($target_file);
     $query = "insert into home_page_images set " . "img_url='" . mysqli_escape_string($link, $img_url) . "', " . "href='" . mysqli_escape_string($link, $href) . "', " . "thumb_url='" . mysqli_escape_string($link, $thumb_url) . "', " . "caption='" . mysqli_escape_string($link, $caption) . "', " . "size='" . mysqli_escape_string($link, $size) . "'";
     $result = mysqli_query($link, $query);
     //Log error
     AdminUtility::logMySQLError($link);
     return $result;
 }
开发者ID:Michaeldgeek,项目名称:NacossUnn,代码行数:70,代码来源:NewsAdmin.php


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