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.
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.
}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.
$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 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 //////////
Hürriyetin sitesine göre ayarlanmıştır. Kodu ceviz den almıştım biraz değiştirdim.
Etiketler: php ile yazı çekmek, php rss konu çekmek, rss çeken php kod, rss ekmek, yazı çeken php kod
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: asp ile php, asp vs php, hangisi daha iyi, php ile geliştirilmiş projeler, php ile yapılmış siteler, php mi asp mi, php vs asp
function emailkontrol($mail)
{
// emaili kontrol et
return preg_match(‘#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si’, $mail);
}
Etiketler: doğru mail mi, mail kontrolü, maili kontrol etmek, php ile mail kontrol
.
<?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');
?>
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.
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
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
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
<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
<?
$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: mail
<?php
$yazi = preg_replace('/(\[(.*?)\])(.*?)(\[(.*?)\])/',' ',$yazi);
echo $yazi;
?>
Etiketler: karakter, preg_replace, silmek