0

当然,这对您的专家来说很容易,我正在尝试将图像上传到站点并保存到数据库的路径。如果可能,如何在保存之前更改图像大小?

这是我在更新时处理更新查询的脚本:

<?php   // Get Event ID
    $update=$_GET['update'];

    // Create Session
    $event_name=$_POST['event_name'];
    $event_description=$_POST['event_description'];
    $event_date=$_POST['event_date'];
    $event_time=$_POST['event_time'];
    $event_cost=$_POST['event_cost'];
    $event_image=$_POST['event_image'];

    // Connection to MySQL Database.
    include ('_includes/_dbconnection.php');
    include ('_includes/_dbopen.php');

    // Update Event using Event ID.

    $sql="UPDATE b_events SET ename = '$event_name', edescription = '$event_description', edate = '$event_date', etime = '$event_time', ecost = '$event_cost', eimage = '$event_image' WHERE id = '$update'";
    $result=mysql_query($sql);

    if($result){
    header('Location: _events.php');
    }

    else {
    header('Location: _home.php');
    }

?>

我在图片的 update.html 中有以下代码:

<input name="event_image" type="file" />

谢谢!!!

4

2 回答 2

0

要更改图像大小必须调整大小。创建具有特定尺寸的副本的功能。

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

来源: http: //php.net/manual/en/function.imagecopyresized.php

于 2012-04-13T07:05:54.537 回答
0

PHP 有用于处理图像的 GD 库:函数 imagecopyresampled 调整图像大小。验证 GD 是否在您的 php 配置中启用 http://us3.php.net/imagecopyresampled

于 2012-04-13T07:06:35.547 回答