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: , , , ,

PHP ile neler yapılmış 01 12 09

PHP mi ASP gibi bir çok soru çıkar insanın karşısına web sitesi kodladığı yada tasarladığı sürece. Bence ikisini de bilmek gerekli. Genelde ASP yada asp den türeyen aspx gibi dil ile kurumsal web siteleri tasarlanır. Microsoft aşıkları için çok idealdir. PHP ise genelde öğrencilere hitap nedeni de her hangi bir ücret ödemeden yüklenen linux sistemlerde sorunsuz ve hızlı bir şekilde çalışmasıdır. En önemlisi de para ödemeye gerek yoktur php için.

PHP ile yapılan bir kaç web sitesine örnek vermek gerekilirse ve bir kaç projese başlıcalarını

www.google.com

www.Youtube.com

www.gmail.com

www.facebook.com u örnek verebiliriz.

PHP ile çalışan sistemler ise blogcu.com blogger.com wordpress.com  gibi blog siteleri , joomla ve php-nuke ile kurulmuş portal siteleri, vbulletin ile kurulan dünyanın en çok ziyaret edilen forum siteleri gibi bir çok örnek verebiliriz.

ASP için ise microsoftun destkelediği siteleri örnek gösterebiliriz. Microsoft biterse asp de biter :)

Etiketler: , , , , , ,

PHP ile mail adresi kontrolü 29 11 09

function emailkontrol($ccc)
{
// emaili kontrol et
return preg_match(‘#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si’, $ccc);
}

function emailkontrol($mail)

{

// emaili kontrol et

return preg_match(‘#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si’, $mail);

}

Etiketler: , , ,

Sitenin title’ını çekip link veren fonksiyon 31 10 09

http://www.csstema.com/php/fonksiyon…fonksiyon.html Orjinal yazım .

PHP- Kodu:
<?php
function link($site)
{
$section = file_get_contents($site);
$icerik='#<title>(.*?)</title>#si';
preg_match($icerik,$section,$d_icerik);
echo
"<a href=\"$site\" title=\"$d_icerik[1]\">$d_icerik[1]</a>";
}
link('http://www.csstema.com');
?>

Etiketler: ,

Cümle İçinde arama yapma 31 10 09

1)

if (eregi(‘http’,$deger)) {
echo ‘http bulundu’;
}

2)

$pos = strpos(‘http’,$deger);

if ($pos !== false) {
echo ‘http bulundu’;
}

3)
$check = explode(‘http’,$deger);
if (count($check) > 1) {
echo ‘http bulundu’;
}

Cümle içerisinde html geçip geçmediğini kontrol ediyor.

Etiketler: , ,

Php’de mail ,Toplu Mail,Gruplu Mail, Mailde Resim ve Html mail Gönderme İşlemleri 31 10 09

Mail isim ve grup adında üç adet alan oluşturuyorsunuz. maile mail adreslerini isime kullanıcı ismini ve grup a da grup id yi alıyorsunuz grup tablosundan. mailgrup tablosuda id ve grup isminden oluşuyor. Ben fck editörü kullandım siz istediğinizi kullana bilirsiniz. Resim adreslerini txt editöre <img src=logo.gif/> şeklinde yazmalısınız.

Grup Tablosu

Kod:
CREATE TABLE `mailgrup` (
  `id` int(11) NOT NULL auto_increment,
  `grup` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;

Mail Tablosu

Kod:
CREATE TABLE `mail` (
  `id` int(11) NOT NULL auto_increment,
  `grupid` int(11) NOT NULL,
  `isim` text NOT NULL,
  `mail` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;

1. toplumail1.php içine

Kod:
<table><tr><td width=”600″><form method=”POST” action=”toplumail.php”>
<p><?
echo ‘<select name=”grupid”>’;
echo(’<option value=”0″>Hepsi</option>’);
$kategoriler = mysql_query(”select * from mailgrup order by grup asc”) or die(mysql_error());
while($katego = mysql_fetch_array($kategoriler))
{
echo(’<option value=”‘.$katego[id].’”>’.$katego[grup].’</option>’);
}
echo ‘</select>’;
?> <br />
<input name=”baslik” type=”text” /><br />
  <?php
// Automatically calculates the editor base path based on the _samples directory.
// This is usefull only for these samples. A real application should use something like this:
// $oFCKeditor->BasePath = ‘/fckeditor/’ ; // ‘/fckeditor/’ is the default value.
$sBasePath = $_SERVER['PHP_SELF'] ;
$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, “_samples” ) ) ;

$oFCKeditor = new FCKeditor(’mesaj’) ;
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Value  = ” ;
$oFCKeditor->Create() ;
?></p>
  <p> </p>
  <p><input type=”Submit” value=”Mail Gönder” name=”B1″><input type=”reset” value=”Temizle” name=”B2″></p>
</form>

</table>

2. toplumail.php içine

Kod:
<?

$mesaj = $_POST[mesaj];
$targetChars=array(’\\’);
$mesaj=str_replace($targetChars, “”, $mesaj);
$baslik = $_POST[baslik];
$grupid= $_POST[grupid];
if ($grupid==’0′) {
$kimegidiyor = mysql_query(”SELECT * FROM mail”); } else {
$kimegidiyor = mysql_query(”SELECT * FROM mail where grupid=’$grupid’ “);
}
while ($gidecek = mysql_fetch_array($kimegidiyor))
{

$mail =$gidecek[mail];
$isim =$gidecek[isim];

 $fromemail=”info@kadinin.com“;
 $fromname=”Gönderen Kişi”;
 $subject=$baslik;
 $address=$mail;
 $text=’
 <html lang=”tr”>
 <head>
 <meta content=”text/html; charset=utf-8″ http-equiv=”Content-Type”>
 <title>Gönderen Kişi</title>
 </head>
 <body>
 Merhaba,<br />
 Sayın’.$isim.’<br /><br />

 ’.$mesaj.’<br /><br />

    www.kadinin.com<br /> mail adresi.com<br />
 http://www.kadinin.com<br />
</body></html>
 ’;

$header = “From: Kadının Sitesi <info@kadinin.com>\n”;
$header .= “X-Sender: <servis@kadinin.com>\n”;
$header .= “X-Mailer: kadinin.com, PHP\n”;
$header .= “X-Priority: 0\n”;
$header .= “Return-Path: <servis@kadinin.com>\n”;

$header .= “Content-Type: text/html; charset=iso-8859-9\n”;
 mail($address,$subject,$text,$header);
echo “Mail Gönderildi $mail<br />”;

}

?>

Etiketler:

İki karakter arasını silmek 31 10 09

<?php
$yazi
= preg_replace('/(\[(.*?)\])(.*?)(\[(.*?)\])/',' ',$yazi);
echo
$yazi;
?>

Etiketler: , ,