2012-04-13 12 views
0

これはあなたの専門家にとっては簡単なことですが、私はサイトに画像をアップロードし、データベースへのパスを保存しようとしています。可能であれば、保存する前に画像サイズを変更するにはどうすればよいですか?イメージをアップロードしてPHPに保存します。

はここで更新するときに、クエリを更新するために、ハンドル私のスクリプトです:

<?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" /> 

感謝を!

+0

http://stackoverflow.com/a/386581/1220835 – Basti

答えて

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

0

PHPは、画像を扱うためのGDライブラリがあります。機能は、画像のサイズを変更imagecopyresampled。 GDがあなたにenalbedされていることを確認してください。 http://us3.php.net/imagecopyresampled

関連する問題