msgbartop
Arama Motoru Optimizasyonu , Scriptler ,Genel Bilgiler ve SEO Makaleleri
msgbarbottom

Creating thumbnail images 16 03 10

Creating thumbnail images is a very common requirement. Many scripts use this to create thumbnails of uploaded images or any stored images. We will learn how to create thumbnail images while uploading images to the server. Please read the tutorials on file upload when register_global is off to know how to upload files to the server with necessary permissions in PHP 5.

The file ( or image ) will be first uploaded to a directory and then one thumbnail image will be created in a different directory. So for creating the thumbnail we will check the file extension ( it is gif or jpeg image ) but to keep the script simple we are not checking here the file size. So if the file size is to be restricted then file size validation is to be added. You can see how the file size checking is done in file upload tutorial.

This script is tested with PHP 5.2.6 with register_global is OFF. Please update your script if you have downloaded the old version of this.

<FORM ENCTYPE=”multipart/form-data” ACTION=”addimgck.php” METHOD=POST>
Upload this file: <INPUT NAME=”userfile” TYPE=”file”>
<INPUT TYPE=”submit” VALUE=”Send File”></FORM>

We will now see the addimgck.php file and check the code to create the thumbnail image. We will upload the file to the upimg directory and check to see if file upload is successful or not.

// Below lines are to display file name, temp name and file type , you can use them for testing your script only//////
echo “File Name: “.$_FILES[userfile][name].”<br>”;
echo “tmp name: “.$_FILES[userfile][tmp_name].”<br>”;
echo “File Type: “.$_FILES[userfile][type].”<br>”;
echo “<br><br>”;
///////////////////////////////////////////////////////////////////////////
$add=”upimg/”.$_FILES[userfile][name]; // the path with the file name where the file will be stored, upload is the directory name.
//echo $add;
if(move_uploaded_file ($_FILES[userfile][tmp_name],$add)){
echo “Successfully uploaded the mage”;
chmod(“$add”,0777);

}else{echo “Failed to upload file Contact Site admin to fix the problem”;
exit;}

Now the image is uploaded to the directory and from that image we will create thumbnail image of it. We will first set the height and width of the thumbnail  images to be  generated. Then we will check the type of the file and now we are checking for file type of gif and jpeg and if the image is not of this type then we are terminating the script giving an error message.

///////// Start the thumbnail generation//////////////
$n_width=100; // Fix the width of the thumb nail images
$n_height=100; // Fix the height of the thumb nail imaage

$tsrc=”thimg/”.$_FILES[userfile][name]; // Path where thumb nail image will be stored
//echo $tsrc;
if (!($_FILES[userfile][type] ==”image/pjpeg” OR $_FILES[userfile][type]==”image/gif”)){echo “Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>”;
exit;}

Now let us start with gif file thumb nail image creation. We will first read the height and width of the uploaded image and then resize it to our thumbnail image size. Note that in some GD library support GIF version is not included so to check that we have used one if condition and  accordingly used jpeg support.  We will be using imagecreatetruecolor to retain the actual color combination of the main picture.

//////////// Starting of GIF thumb nail creation///////////
if (@$_FILES[userfile][type]==”image/gif”)
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists(“imagegif”)) {
Header(“Content-type: image/gif”);
ImageGIF($newimage,$tsrc);
}
elseif (function_exists(“imagejpeg”)) {
Header(“Content-type: image/jpeg”);
ImageJPEG($newimage,$tsrc);
}
chmod(“$tsrc”,0777);
}////////// end of gif file thumb nail creation//////////

////////////// starting of JPG thumb nail creation//////////
if($_FILES[userfile][type]==”image/pjpeg”){
$im=ImageCreateFromJPEG($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod(“$tsrc”,0777);
}
//////////////// End of JPG thumb nail creation //////////

Etiketler: , ,

Php ile RSS den veri çekmek 29 12 09

Hürriyetin sitesine göre ayarlanmıştır. Kodu ceviz den almıştım biraz değiştirdim.

<html>
<head>
<META HTTP-EQUIV=”Content-Type” CONTENT=”text/html; charset=utf8″>
<meta http-equiv=”content-language” content=”TR”>
<META NAME=”Pragma” CONTENT=”no-cache”>
<META HTTP-EQUIV=”cache-control” CONTENT=”no-cache”>
<META HTTP-EQUIV=”Expires” CONTENT=”29.12.2009 20:18:18″>
<link REL=”SHORTCUT ICON” HREF=”/images/hurlogo.ico”>
</head>
<body marginwidth=’0′ marginheight=’0′ leftmargin=’1′ topmargin=’1′ bgcolor=’#FFFFFF’>
<?php
//Coded By RMx
// Kodlar başlıyor.:)
// fonksiyon tanmılayalım…
function salla($rmx) {
//XML ayarlarım…
$xmldosya = fopen($rmx, ‘r’);
if (!$xmldosya) die(‘xml dosyasını okuyamadım :(‘);
$oku = fread($xmldosya ,40000);
//parçalama işlemlerim:)
$aq = eregi(“<item>(.*)</item>”, $oku ,$huseyin);
$nihaha = explode(“<item>”, $huseyin[0]);
$yat = count($nihaha);
// Font ayarlarım…
echo ‘<font face=verdana><ul>’;
// döngü kurayım hemen diğer linkleri de almak için…
for($i=1 ; $i<=$yat-1 ;$i++) {
//RSS adresini yazdığım sitenin içinden almak istediğim
//Bilgilerin taglarının içinden bilgileri alıyorum…
ereg(“<title>(.*)</title>”,$nihaha[$i], $baslik);
ereg(“<link>(.*)</link>”,$nihaha[$i], $linkler);
ereg(“<description>(.*)</description>”,$nihaha[$i], $aciklama);
echo str_replace(‘RMx’,'a’,”<li><font style=’font-size: 12px;’><RMx target=_blank href =’$linkler[1]‘\>”.($baslik[1]).”</RMx></font>”);
echo “<br><font color=gray style=’font-size: 10px;’>”.($aciklama[1]).”</font></li>”;
}
}
//RSS okuyucumuzun başlığını koyalım…
echo ‘<h1>Coderx RSS Okuyucu</h1>’;
// Yazdığımız fonksiyonu okutalım…
$xml = ‘http://rss.hurriyet.com.tr/rss.aspx?sectionId=1′;
// Ben örnek olarak milw0rmun rss adresini aldım.. Siz istediğiniz gibi değişin:)
// Haberleri almak için yazmıştım ama her türlü rss okuyabilirsiniz…
salla($xml);
//Bitti:)
?>
</body>
</html>

Etiketler: , , , ,

CSharp ile ilgili yazılarıma csharpkitabi.com sitemde devam edeceğim 24 12 09

CSharp ile ilgili yazılarıma bundan sonra www.csharpkitabi.com sitemde devam edeceğim.

Etiketler:

textBox’a Sadece sayı girilsin + backspace tuşu çalışsın 21 12 09

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false && e.KeyChar!=8)
e.KeyChar = ‘\0′;
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{

if (char.IsDigit(e.KeyChar) == false && e.KeyChar!=8)

e.KeyChar = ‘\0′;

}

Etiketler: , , , , ,

textBox’a sadece sayı girişi yaptırmak 20 12 09

textBox’ın keypress olayına aşağıdaki kodu yazıyoruz.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string str = “0123456789″;
if (str.IndexOf(e.KeyChar) == -1)
e.KeyChar = ‘\0′;
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{

string str = “0123456789″;

if (str.IndexOf(e.KeyChar) == -1)

e.KeyChar = ‘\0′;

}

Etiketler: , , ,

CSharp MessageBoxButtons kullanımı 11 12 09

Message box örnekleri

DialogResult Olay = MessageBox.Show(“Bu satır silinecek”,”Onaylama”,MessageBoxButtons.YesNoCancel,MessageBoxIcon.Exclamation);

if (DialogResult.Yes == Olay)

MessageBox.Show(“Yes düğmesi tıklandı”);

if (DialogResult.No == Olay)

MessageBox.Show(“No düğmesi tıklandı”);

if (DialogResult.Cancel == Olay)

MessageBox.Show(“Cancel düğmesi tıklandı”);

DialogResult Onay = MessageBox.Show(“düğme tıkla”,”deneme”,MessageBoxButtons.AbortRetryIgnore);

if (DialogResult.Abort == Onay)

MessageBox.Show(“Abort düğmesi tıklandı”);

if (DialogResult.Ignore == Onay)

MessageBox.Show(“Ignore tuşu tıklandı”);

if (DialogResult.Retry == Onay)

MessageBox.Show(“Retry düğmesi tıklandı”);

Etiketler: , , ,

Aralık ayının kelimesi 04 12 09

Elma Krom

Bayanların son günlerde arayıp en sık tıkladıkları kelimeler. :) Web sitesi yapan çoğu kişi bilir hanımlar için yapılan siteler daha çok gelir getirir.

Etiketler: , , ,

HTML Bağlantıyı Yeni Sekmede Açma – Yeni Sekmeye Link Verme 03 12 09

Link konu aşağıdaki gibi yazılır.

<a href=”http://www.seoarşivi.com” title=”Seo Arşivi” >Seo Arşivi</a>

Yeni sekmede açtırmak için target=” _blank ” kodunu href ten önce ekliyoruz ve _blank kelimesinin önüne ve sonuna bir karakter boşluk bırakıyorsunuz tırnakların içerisine.

<a target=” _blank ” href=”http://www.seoarşivi.com” title=”Seo Arşivi” >Seo Arşivi</a>

Etiketler: , , ,

Asal sayımı değilmi 03 12 09

Klavyeden girilecek bir sayının asal sayı olup olmadığını ekrana basan bir program yazınız

int sayi, i;

//Sayıyı ilk başta asal kabul ediyoruz.

//asal_mi değişkeni 1 ise, sayi asaldir.

int asal_mi = 1;

//Klavyeden, test edilmek üzere bir sayı alınıyor.

sayi =Convert.ToInt32(Console.ReadLine());

//Girilen sayının, başka sayılara göre sırayla modunu

//alıyoruz. Bir sayının modunu aldığınızda, kalan 0 ise

//bu sayının bölünebildiğine ve dolayısıyla

//asal olmadığına dair bilgi verir. Bu işlemi yapabilmek

//için 2′den başlayarak, sayının yarısına kadar olan

//bütün değerler deneniyor.

for( i = 2; i < sayi; i++ ) {

if( sayi%i == 0 ) {

//Sayı i değişkenine kalansız bölünmektedir.

//Dolayısıyla, sayı asal değildir ve döngüyü

//sürdürmeye gerek yoktur.

asal_mi = 0;

break;

}

}

//Sayının asal olup olmama durumuna göre, çıktı yazdırılıyor.

if( asal_mi == 1 )

Console.WriteLine( “{0} sayısı asaldır.\n”, sayi );

else

Console.WriteLine( “{0} sayısı asal değildir.\n”, sayi );

Etiketler: , , , ,

Üçgenmi Değilmi 03 12 09

Bir üçgende, iki kenarın toplam uzunluğu, üçüncü kenardan az olamaz. Ayrıca iki kenarın birbirinden farkının mutlak değeri, üçüncü kenardan büyük olmamalıdır. Bu bilgileri kullanarak, verilen üç kenar uzunluğuna göre bir üçgen çizilip çizilmeyeceğini gösteren programı yazınız. Girilecek kenar uzunlukları tam sayı olacaktır.

int a, b, c;

int temp;

a = Convert.ToInt32(Console.ReadLine());

b = Convert.ToInt32(Console.ReadLine());

c = Convert.ToInt32(Console.ReadLine());

/* a ile b den buyuk olan a ya kucuk olan b ye atanir */

if (a < b)

{

temp = a;

a = b;

b = temp;

}

if (((a + b) <= c) || ((a – b) >= c))

Console.WriteLine(“Bu kenar uzunluklarina sahip bir ucgen olamaz.\n”);

else

Console.WriteLine(“Bu kenar uzunluklarina sahip bir ucgen cizilebilir.\n”);

Etiketler: ,