| | |
upload files hlp
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I use the similar on my store2go site. You can do it in two ways:
1. Upload image and instantly create a thumbnail. See code:
[php]
// if jpg use
$src_img=ImageCreateFromJpeg($uploadedfile);
// else if gif use
$src_img=ImageCreateFromGif($uploadedfile);
// and for png use
$src_img=ImageCreateFromPng($uploadedfile);
// create the scaled instance for thumbnail in GIF
$dst_img=imagecreatetruecolor($thumb_width,$thumb_height);
ImageCopyResampled($dst_img,$src_img,0,0,0,0,$thumb_width,$thumb_height,$mywidth,$myheight);
// write the damned thing to disk
ImageGif($dst_img,"uploaddir/thumbnail.gif");
[/php]
2. Upload image and resize to the acceptable resolution (say 800x600 max). When displaying the thumb and link, simply resize the resized image using code below:
[php]
$size = GetImageSize($image);
$width = round($size[0]);
$height = round($size[1]);
$percentage = 1;
// set target thumbnail size
$targetw = 100;
$targeth = 75;
// reduce image to target dimensions
if ($width > $height) {
if ($width > $targetw) $percentage = ($targetw / $width);
}
else {
if ($height > $targeth) $percentage = ($targeth / $height);
}
$width = round($width * $percentage);
$height = round($height * $percentage);
echo '<a href="'.$image.'"><img src="'.$image.'" border="0" alt="" width="'.$width.'" height="'.$height.'"></a>';
[/php]
1. Upload image and instantly create a thumbnail. See code:
[php]
// if jpg use
$src_img=ImageCreateFromJpeg($uploadedfile);
// else if gif use
$src_img=ImageCreateFromGif($uploadedfile);
// and for png use
$src_img=ImageCreateFromPng($uploadedfile);
// create the scaled instance for thumbnail in GIF
$dst_img=imagecreatetruecolor($thumb_width,$thumb_height);
ImageCopyResampled($dst_img,$src_img,0,0,0,0,$thumb_width,$thumb_height,$mywidth,$myheight);
// write the damned thing to disk
ImageGif($dst_img,"uploaddir/thumbnail.gif");
[/php]
2. Upload image and resize to the acceptable resolution (say 800x600 max). When displaying the thumb and link, simply resize the resized image using code below:
[php]
$size = GetImageSize($image);
$width = round($size[0]);
$height = round($size[1]);
$percentage = 1;
// set target thumbnail size
$targetw = 100;
$targeth = 75;
// reduce image to target dimensions
if ($width > $height) {
if ($width > $targetw) $percentage = ($targetw / $width);
}
else {
if ($height > $targeth) $percentage = ($targeth / $height);
}
$width = round($width * $percentage);
$height = round($height * $percentage);
echo '<a href="'.$image.'"><img src="'.$image.'" border="0" alt="" width="'.$width.'" height="'.$height.'"></a>';
[/php]
Ecommerce-Web-Store.com Building Your e-Business.
![]() |
Similar Threads
- validate-upload file (ASP.NET)
- upload images and store the location in a database (PHP)
- unable to upload files or send email on wireless (Windows NT / 2000 / XP)
- Cannot Upload files or send email on wireless (Web Browsers)
- how to Upload files using Linux bash Shell scripting and CGI (Shell Scripting)
- How To Upload in PHP (PHP)
- Cant upload dreamweaver "files folder" to site (Networking Hardware Configuration)
Other Threads in the PHP Forum
- Previous Thread: Help With Messages in Mysql Stop Overwriting
- Next Thread: about shopping center
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array basic beginner binary broken cakephp checkbox class cms code confirm cron curl database date directory display download dynamic echo email eregi error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla keywords ldap limit link login loop mail mediawiki menu mlm mod_rewrite multiple mycodeisbad mysql oop parse paypal pdf php phpincludeissue problem query radio random recursion regex remote script search seo server sessions sms snippet soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube





