arkadaşlar süper bir kod buldum php upload class burada sizinle paylaşayım dedim.belki birilerinin işine yarıyabilir.şimdi bu kodlarla resimi upload yapıyorum resmi boyutlandırabiliyorum üstüne yazı yazabiliyorum db ye kayıt yapabiliyorum FAKAT dosya isimlerini değştiremiyorum yani her dosyaya farklı bir isim verdiremiyorum db kabul etmiyor.her türlü yolu denedim class bilgim az LÜTFEN YARDIM EDİN.
<?php
include "../Connections/baglan.php";
$rand =substr(md5(uniqid(rand())),0,5);
class resim {
var $uzanti;
var $resimyol;
var $yol='res/';
var $max_en='200';
var $max_boy='200';
var $font='116.ttf';
var $fontsize='15';
var $filtre = array("jpg","jpeg","png","gif");
var $yazi = 'Ozsari Grup';
function kontrol($veri)
{
$rsm = pathinfo($veri);
@$this->uzanti = strtolower($rsm['extension']);
if(!in_array($this->uzanti,$this->filtre))
{
//Ýzin verilmeyen format..
die();
}
}
function yukle($veri)
{
$this->resimyol = $this->yol.$veri.'.'.$this->uzanti;
@move_uploaded_file($_FILES['resim']['tmp_name'], $this->resimyol);
}
function resize_logobas()
{
$boyut = getimagesize($this->resimyol);
$en = $boyut[0];
$boy = $boyut[1];
$x_oran = $this->max_en / $en;
$y_oran = $this->max_boy / $boy;
if (($en <= $this->max_en) and ($boy <= $this->max_boy))
{
$son_en = $en;
$son_boy = $boy;
}
elseif (($x_oran * $boy) < $this->max_en)
{
$son_en = $this->max_en;
$son_boy = ceil($x_oran * $boy);
}
else
{
$son_en = ceil($y_oran * $en);
$son_boy = $this->max_boy;
}
switch ($this->uzanti)
{
case "gif"; $eski = imagecreatefromgif($this->resimyol); break;
case "png"; $eski = imagecreatefrompng($this->resimyol); break;
default: $eski = imagecreatefromjpeg($this->resimyol);
}
$yeni = imagecreatetruecolor($son_en,$son_boy);
imagecopyresampled($yeni,$eski,0,0,0,0,$son_en,$son_boy,$en,$boy);
$renk = imagecolorallocate( $yeni, 255, 255, 255 );
$size = imagettfbbox($this->fontsize,0,$this->font,$this->yazi);
$yazi_en = abs($size[2]-$size[0]);
$yazi_boy = abs($size[3]-$size[5]);
$yazix = $son_en-5-$yazi_en;
$yaziy = $son_boy-5;
imagettftext($yeni,$this->fontsize,0,$yazix,$yaziy,$renk,$this->font,$this->yazi);
switch ($this->uzanti)
{
case "gif"; imagegif($yeni,$this->resimyol); break;
case "png"; imagepng($yeni,$this->resimyol); break;
default: imagejpeg($yeni,$this->resimyol);
}
imagedestroy($eski);
imagedestroy($yeni);
}
}//class
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE konut SET resim=%s WHERE id=%s",
GetSQLValueString($_FILES["resim"]["name"], "text"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_baglan, $baglan);
$Result1 = mysql_query($updateSQL, $baglan) or die(mysql_error());
}
$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_baglan, $baglan);
$query_Recordset1 = sprintf("SELECT * FROM konut WHERE id = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $baglan) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<form name="form1" method="post" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data">
<fieldset style="width: 336px; height: 128px">
<legend>Ana Resim </legend>
<p align="center">
<input type="file" name="resim">
<br>
<br>
<input type="submit" value="Gönder" name="B1">
<br>
<input type="hidden" name="MM_update" value="form1">
<input name="id" type="hidden" id="id" value="<?php echo $row_Recordset1['id']; ?>" />
</fieldset>
</form>
<?
$resim = new resim();
@$resim->kontrol($_FILES["resim"]["name"]);
$resim->yukle(substr($_FILES["resim"]["name"],0, -4));
$resim->resize_logobas();
echo '<font color = #009900><b>Dosyaniz basarili bir sekilde yuklendi!</b></font>';
?>