Resim UPLOAD Et & MySQL V.T. Kaydet Gönderen: cemaliozan Tarih: 02 October 2007 21:11:48
Resimlerin yüklendi ASPX sayfası
Kodlama dili (asp)
<%@ Page language="c#" Debug="true" Codebehind="m_resimekle.pas" AutoEventWireup="false" Inherits="m_uyeresimekle.TWebFormm_Resim_Ekle" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Yeni Resim Ekleyin</title>
<meta http-equiv="Content-Language" content="tr">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="./css/ana.css" />
<link rel="stylesheet" type="text/css" href="./css/profil_tabview.css" />
<style type="text/css">.gonderbutton {
BORDER-RIGHT: medium none; PADDING-RIGHT: 2px; BORDER-TOP: medium none; PADDING-LEFT: 2px; BACKGROUND-IMAGE: url(img/nr_bck.gif); PADDING-BOTTOM: 2px; FONT: bold 9pt tahoma,arial,verdana; OVERFLOW: visible; BORDER-LEFT: medium none; WIDTH: 70px; CURSOR: hand; COLOR: #000054; PADDING-TOP: 2px; BORDER-BOTTOM: medium none; HEIGHT: 25px
}
</style>
<link rel="stylesheet" type="text/css" href="./css/profil.css" />
<SCRIPT LANGUAGE="JavaScript">
<!-- Gizle
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</SCRIPT>
<script type="text/javascript">
<!--
function resim_goster(islem, ry, resim) {
rdiv = document.getElementById(ry);
if (islem == 0)
rdiv.style.display = 'none';
else {
rdiv.innerHTML = '<img src="' + resim + '" width="300" height="225">';
rdiv.style.display = '';
rdiv.style.background = '';
tb = document.getElementById("TextBox_resim_adi");
tb.value = "Resim";//resim;
}
}
//-->
</script>
</head>
<body style="BACKGROUND-IMAGE: url(img/gradinent/dino.gif)" onunload="JavaScript:opener.ListeyiYenile();">
<form enctype="multipart/form-data" runat="server">
<table style="WIDTH: 100%">
<tr>
<td class="etiket9pt" style="WIDTH: 69px">Resim Seçin</td>
<td class="etiket9pt">
<input id="dosya" type="file" name="dosya" viewstate="true" runat="server" class="editbox" onchange="resim_goster(1,'resimdiv',this.value);" title="Eklenecek Resmi Seçin"></td>
<td class="etiket9pt">
</td>
</tr>
<tr>
<td colspan="3">
<table style="WIDTH: 100%">
<tr>
<td class="etiket9pt" style="WIDTH: 79px">Albüm Adı</td>
<td>
<ASP:DropDownList id="DropDownList_Album" runat="server" cssclass="editbox"></ASP:DropDownList></td>
<td class="etiket9pt">
</td>
</tr>
<tr>
<td class="etiket9pt" style="WIDTH: 79px">Resim Adı</td>
<td>
<ASP:TextBox id="TextBox_resim_adi" runat="server" CssClass="editbox"></ASP:TextBox></td>
<td class="etiket9pt">
<ASP:CheckBox id="CheckBox_Ozel" runat="server" text="Yalnızca arkadaşlarım görebilir" enableviewstate="False"></ASP:CheckBox>
</td>
</tr>
<tr>
<td class="etiket9pt" style="WIDTH: 79px">kategori</td>
<td>
<ASP:TextBox id="TextBox_Kategori" runat="server" CssClass="editbox" enableviewstate="False"></ASP:TextBox></td>
<td class="etiket9pt">
</td>
</tr>
<tr>
<td colspan="3" class="etiket9pt">Resim Açıklaması
<input size="5" name="thisSayac" id="thisSayac" value="1000" class="readonlyeditbox" readonly="true"> Karakter kaldı...</td>
</tr>
<tr>
<td colspan="3" class="etiket9pt">
<asp:TextBox runat="server" id="TextBox_resim_aciklama" TextMode="MultiLine" Rows="4" Width="99%" CssClass="editbox"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3" align="center" class="etiket8pt">
<ASP:Label
id="Label_Msg" runat="server" enableviewstate="False">Yükleyeceğiniz resimlerin formatı jpg veya gif ve dosya büyüklüğü max. 512 KB olmalıdır.</ASP:Label></td>
</tr>
<tr>
<td colspan="3" align="center">
<ASP:Button id="Button_Kapat" runat="server" text=" Kapat " enableviewstate="False" cssclass="gonderbutton" CausesValidation="False"></ASP:Button>
<asp:Button runat="server" Text=" Ekle " id="Button_Ekle" cssclass="gonderbutton" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" class="etiket11pt" style="FONT-WEIGHT: 900; FONT-SIZE: 16pt; BACKGROUND-IMAGE: url(img/gradinent/marigold.gif); COLOR: #cc3300; FONT-FAMILY: tahoma, Helvetica, Verdana, Arial" align="center" valign="middle">
<ASP:Label id="Label_Eklenen" runat="server">0 Resim Eklendi</ASP:Label></td>
</tr>
<tr>
<td colspan="3" style="BORDER-RIGHT: #fdefc6 2px dotted; BORDER-TOP: #fdefc6 2px dotted; BORDER-LEFT: #fdefc6 2px dotted; BORDER-BOTTOM: #fdefc6 2px dotted" align="center" valign="middle">
<div id="resimdiv" style="BACKGROUND-POSITION: center center; BACKGROUND-IMAGE: url(img/resimgoster.jpeg); WIDTH: 100%; BACKGROUND-REPEAT: no-repeat; HEIGHT: 225px; TEXT-ALIGN: center">
<ASP:Label id="Label_Resim" runat="server" enableviewstate="False">***</ASP:Label>
</div>
</td>
</tr>
<tr>
<td class="etiket8pt" colspan="3" align="center" valign="middle"><ASP:Label id="Label_KullanimDurumu" runat="server">Size ayrılan 1024 KB. Alanın 512 KB. Bölümünü Kullanıyorsunuz. Toplam 4096 Kb. Kullanılabilir Alanınız Mevcut...</ASP:Label></td>
</tr>
</table>
</form>
</body>
</html>
Resimleri basan bir yordam...
Kodlama dili (delphi)
procedure TWebUserControl_pg_resimpaylasyorumekle.ResimleriBas(Const UID,AID,ResimID:String);
Var
Baglantim : MySqlConnection;
Komutcu : MySqlCommand;
Okuyucu : MySqlDataReader;
TamEkran : String;
begin
try
TamEkran := '';
Baglantim := MySqlConnection.Create(GetBaglantiText);
Komutcu := MySqlCommand.Create('select * from tbl_resimler where id="'+ResimID+'"',Baglantim);
Baglantim.Open;
Okuyucu := Komutcu.ExecuteReader;
if Okuyucu.Read then
begin
TamEkran := '<a href="http://'+GetSiteAdresi+UyelerResimKlasoru+AID+'/orj/'+Okuyucu.Item['bresim_dosyasi'].ToString+'" Title="'+Okuyucu.Item['resim_adi'].ToString+' İsimli resmi orjinal boyutlarında göster" target="_blank">';
Label_Resim_Adi.Text := StrToHTml(Okuyucu.Item['resim_adi'].ToString);
Label_KResim_Dosyasi.Text := TamEkran+ResimGoster(AID, Page.Server.MapPath(Sabitler.UyelerResimKlasoru+AID+'/'+Okuyucu.Item['bresim_dosyasi'].ToString),Okuyucu.Item['bresim_dosyasi'].ToString)+'</a>';
Label_Resim_Aciklama.Text := StrToHtml(Okuyucu.Item['resim_aciklama'].ToString);
end;
finally
Komutcu.Free;
Baglantim.Close;
Baglantim.Free;
end;
end;
Resim upload edip veri tabanına kaydetme yordamları
Kodlama dili (delphi)
procedure TWebForm_Profilim_Uye_Resim_Ekle.YuklenebilecekResimBoyutu(Const UID:String;Out Ayrilan,KullanilanYer,BosYer : Double);
Var
Baglantim : MySqlConnection;
Komutcu : MySqlCommand;
Okuyucu : MySqlDataReader;
Begin
Try
Ayrilan := 0;
KullanilanYer := 0;
BosYer := 0;
Baglantim := MySqlConnection.Create(GetBaglantiText);
Komutcu := MySqlCommand.Create('Select resim_size From uyeler Where id="'+UID+'"',Baglantim);
Baglantim.Open;
Okuyucu := Komutcu.ExecuteReader;
if Okuyucu.Read then
begin
Ayrilan := Okuyucu.GetDouble(0);
Okuyucu.Close;
end;
Komutcu := MySqlCommand.Create('Select sum(bresim_size) as kullanilan From tbl_resimler Where uye_id="'+UID+'"',Baglantim);
Okuyucu := Komutcu.ExecuteReader;
if Okuyucu.Read then
begin
KullanilanYer := Okuyucu.GetDouble(0);
Okuyucu.Close;
end;
Komutcu := MySqlCommand.Create('Select count(id) as toplam From tbl_resimler Where uye_id="'+UID+'"',Baglantim);
Okuyucu := Komutcu.ExecuteReader;
if Okuyucu.Read then
begin
Label_Eklenen.Text := 'Klasörünüzde '+Okuyucu.Item['toplam'].ToString+' Resim Var...';
Okuyucu.Close;
end else
Label_Eklenen.Text := 'Kayıtlı Resim Yok';
BosYer := Ayrilan - KullanilanYer;
Finally
Komutcu.Free;
Baglantim.Close;
Baglantim.Free;
end;
END;
Function TWebForm_Profilim_Uye_Resim_Ekle.tbl_resimler_Insert(UID,BResimDosyasi,KResimDosyasi,bEn,bBoy,bSize,kEn,kBoy,kSize,kategori:String):Int16;
Var
Baglantim : MySqlConnection;
Komutcu : MySqlCommand;
Okuyucu : MySqlDataReader;
KayitSayisi : Int16;
Begin
KayitSayisi := 0;
Try
Baglantim:= MySqlConnection.Create(GetBaglantiText);
Komutcu := MySqlCommand.Create('INSERT INTO tbl_resimler (uye_id,resim_adi,resim_aciklama,'+
'resim_gonderme_tarihi,bresim_dosyasi,bresim_en,bresim_boy,bresim_size,kresim_dosyasi,kresim_en,kresim_boy,kresim_size,kategori,'+
'album_id,album_adi,ozel) VALUES('+
'"'+UID+'" ,'+
'"'+IlkHarfBuyuk(Duzelt(TextBox_resim_adi.Text))+'" ,'+
'"'+IlkHarfBuyuk(Duzelt(TextBox_resim_aciklama.Text))+'" ,'+
'"'+Sabitler.GetBugun+'" ,'+
'"'+bResimDosyasi+'" ,'+
'"'+bEn+'" ,'+
'"'+bBoy+'" ,'+
'"'+bSize+'" ,'+
'"'+kResimDosyasi+'" ,'+
'"'+kEn+'" ,'+
'"'+kBoy+'" ,'+
'"'+kSize+'" ,'+
'"'+IlkHarfBuyuk(Duzelt(kategori))+'" ,'+
'"'+DropDownList_Album.SelectedValue+'" ,'+
'"'+DropDownList_Album.SelectedItem.Text+'" ,'+
'"'+CheckIsareti(CheckBox_ozel.Checked)+'")',Baglantim);
Baglantim.Open;
KayitSayisi := Komutcu.ExecuteNonQuery;
Finally
Komutcu.Free;
Baglantim.Close;
Baglantim.Free;
Result := KayitSayisi;
end;
END;
function TWebForm_Profilim_Uye_Resim_Ekle.ResimEklenebilirmi:Boolean;
Var
S : String;
begin
Result := False;
S := '';
if Dosya.PostedFile.FileName = '' then
begin
S := 'Yüklemek İçin Önce Bir Dosya Seçin...<br />';
end;
if (Dosya.PostedFile.ContentType <> 'image/pjpeg') and (Dosya.PostedFile.ContentType <> 'image/gif') then
begin
S := 'JPEG veya Gif Formatlı Resim Yüklemelisiniz...<br />';
end;
if Dosya.PostedFile.ContentLength > Sabitler.UyeHerResimMaxKB then
begin
S := 'Yüklenecek Resim Dosyası Max.'+Convert.ToString(Sabitler.UyeHerResimMaxKB)+' Kb. Olmalı';
end;
if ViewState['bosyer'] <> Nil then
begin
if Convert.ToDouble(ViewState['bosyer'].ToString) <= (Dosya.PostedFile.ContentLength) then
S := 'Toplam '+SayiFormatla(Convert.ToDouble(ViewState['bosyer'].ToString),True,2)+' KB. Boş Yeriniz Var.'+
'Yüklemek İstediğiniz Dosya '+SayiFormatla(Dosya.PostedFile.ContentLength,True,2)+' KB. Yeterli Yer Yok !';
end;
Label_Msg.Text := S;
Result := S = '';
end;
function TWebForm_Profilim_Uye_Resim_Ekle.ResimYukle(Const ID : String; out ResimDosyasiAdi:String):Boolean;
Var
DosyaKlasoru : String;
DosyaAdi : String;
TamYol : String;
OrjYol : String;
DosyaKontrol : String;
I : Integer;
KisaResimDosyaAdi : String;
AResim : System.Drawing.Image;
AResimStream : Filestream;
Oranti,x,y : Double;
OrjinalX,OrjinalY : Double;
ResimFormat : ImageFormat;
AFileInfo : FileInfo;
OFileInfo : FileInfo; // orjinaldosya bilgileri
bEn,bBoy,bSize,
kEn,kBoy,kSize : String;
begin
TamYol := '';
OrjYol := ''; // orjinal kopya için
Result := False;
if Dosya.PostedFile.ContentType = 'image/pjpeg' then
ResimFormat := ImageFormat.Jpeg
else
if Dosya.PostedFile.ContentType = 'image/gif' then
ResimFormat := ImageFormat.Gif
else
ResimFormat := ImageFormat.Jpeg;
// Üyenin resimlerinin saklanacağı klasör uyeler/resimler/1/ şeklinde 1= üye ID
DosyaKlasoru := Server.MapPath(Sabitler.UyelerResimKlasoru+ID);
// Thumb boyutlu resim için Klasör yoksa yarat
if Not &Directory.Exists(DosyaKlasoru) then &Directory.CreateDirectory(DosyaKlasoru);
// Orjinal boyutlu resim için Klasör yoksa yarat
if Not &Directory.Exists(DosyaKlasoru+'\orj') then &Directory.CreateDirectory(DosyaKlasoru+'\orj');
DosyaAdi := Path.GetFileName(Dosya.PostedFile.FileName);
//* Her Halükarda Bu ismi tabloya kaydediyoruz...*//
KisaResimDosyaAdi := DosyaAdi;
//sunucuya kayıt edilecek konum ve dosya
TamYol := Path.Combine(DosyaKlasoru,DosyaAdi);
OrjYol := Path.Combine(DosyaKlasoru+'\orj',DosyaAdi);
//Sunucuda bu isimde bir dosya varsa yeni isim seç - Dosya isimleri benzersiz olmalı
//Burası benzer dosya adlarından dolayı sistemi yavaşlatabilir, tablonun bir alanı ile çalışmak gerek...
I := 0;
While &File.Exists(TamYol) do
begin
DosyaKontrol := 'ur_'+I.ToString+'_'+DosyaAdi;
KisaResimDosyaAdi := DosyaKontrol;
TamYol := Path.Combine(DosyaKlasoru,DosyaKontrol);
OrjYol := Path.Combine(DosyaKlasoru+'\Orj',DosyaKontrol);
Inc(I);
end;
if TamYol <> '' then
begin
ResimDosyasiAdi := '<img src="'+Sabitler.UyelerResimKlasoru+ID+'/'+KisaResimDosyaAdi+'" border="0" />'
end else
ResimDosyasiAdi := '';
//Dosyayi yükle
try
// Geçici dosyayı yüklüyoruz... sondaki ~ bu dosya sileceğimizden koyduk...
Dosya.PostedFile.SaveAs(TamYol+'~');
// Yeniden boyutlandır *//
AResimStream := Filestream.Create(TamYol+'~',Filemode.Open);
Aresim := System.Drawing.Image.FromStream(AResimStream);
X := AResim.Width;
Y := AResim.Height;
// orjinal kopya için //
OrjinalX := X;
OrjinalY := Y;
// orjinal kopyayı kaydet
AResim := AResim.GetThumbnailImage(Convert.ToInt32(OrjinalX),Convert.ToInt32(OrjinalY),nil,nil);
AResim.Save(OrjYol,ResimFormat);
OFileInfo := FileInfo.Create(OrjYol);
bSize := Convert.ToString(OFileInfo.Length);
bEn := Convert.ToString(AResim.Width);
bBoy := Convert.ToString(AResim.Height);
//thumbal görüntü//
Oranti := 1;
//aspect ratio algoritması //
if X > Y then
Oranti := X / Sabitler.UyeKResimBoy
else
Oranti := Y / Sabitler.UyeKResimBoy;
X := X / Oranti;
Y := Y / Oranti;
try
AResim := AResim.GetThumbnailImage(Convert.ToInt32(X),Convert.ToInt32(Y),nil,nil);
AResim.Save(TamYol,ResimFormat);
AFileInfo := FileInfo.Create(TamYol);
kSize := Convert.ToString(AFileInfo.Length);
kEn := Convert.ToString(AResim.Width);
kBoy := Convert.ToString(AResim.Height);
tbl_resimler_Insert(ID,KisaResimDosyaAdi,KisaResimDosyaAdi,bEn,bBoy,bSize,kEn,KBoy,KSize,IlkHarfBuyuk(Duzelt(TextBox_Kategori.Text)));
finally
AFileInfo.Free;
AResimStream.Close;
AResim.Dispose;
if &File.Exists(TamYol+'~') then &File.Delete(TamYol+'~');
end;
Result := True;
except on E:Exception do
Result := False;
end;
end;