Honesty Rocks! truth rules.

Image Upload ??

HOME      >>       Programming

alex1985

I need the image upload script which automatically resized the image by specified size and store it in the specified folder.


oestergaard

google is your friend


alex1985

So, rude! The forums are created for the aim of helping and assisting people!


jlhaslip

Google results show 126,000 responses :

 

Might want to also check out Hotscripts.com : http://forums.xisto.com/no_longer_exists/ Try the third one on the Hotscripts list, for example. http://www.hotscripts.com/listing/free-image-resizing-script/ Free, recent and the GD Library is installed on your Xisto account, so it should work fine here.

 


burhan

Here is great class for image resize http://www.phpclasses.org/package/1450-PHP-Resize-image-from-files-in-different-formats-.html

You can also try http://www.pictarget.com/, they are resizing image and storing in their server.


alex1985

Ok, I will try to create my own.


obiesan

You can use GD_LIB on php, to regenerate new Image with custom resolution. For the class img, u can find in phpclasses.org


alex1985

Thanks.


iGuest

I need the image upload script which automatically resized the image by specified size and store it in the specified folder.

Image Upload

 

Replying to alex1985

 

Try this

==============

 

<?php

 

// Connect to database

 

$errmsg = "";

If (! @mysql_connect("localhost","root","admin")) {

$errmsg = "Cannot connect to database";

}

@mysql_select_db("example");

 

// First run ONLY - need to create table by uncommenting this

// Or with silent @ we can let it fail every sunsequent time ;-)

 

$q = <<<CREATE

Create table pix (

pid int primary key not null auto_increment,title text,imgdata longblob)

CREATE;

@mysql_query($q);

 

// Insert any new image into database

 

If ($_REQUEST[completed] == 1) {

// Need to add - check for large upload. Otherwise the code

// will just duplicate old file ;-)

// ALSO - note that latest.Img must be public write and in a

// live appliaction should be in another (safe!) directory.

Move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.Img");

$instr = fopen("latest.Img","rb");

$image = addslashes(fread($instr,filesize("latest.Img")));

if (strlen($instr) < 149000) {mysql_query ("insert into pix (title, imgdata) values ("".$_REQUEST[whatsit]."", "".$image."")");

} else {

$errmsg = "Too large!";

}

}

 

// Find out about latest image

 

$gotten = @mysql_query("select * from pix order by pid desc limit 1");

If ($row = @mysql_fetch_assoc($gotten)) {

$title = htmlspecialchars($row[title]);

$bytes = $row[imgdata];

} else {

$errmsg = "There is no image in the database yet";

$title = "no database image available";

// Put up a picture of our training centre

$instr = fopen("../wellimg/ctco.Jpg","rb");

$bytes = fread($instr,filesize("../wellimg/ctco.Jpg"));

}

 

// If this is the image request, send out the image

If ($_REQUEST[gim] == 1) {

Header("Content-type: image/jpeg");

print $bytes;

exit ();

}

 

?>

 

<html><head>

<title>Upload an image to a database</title>

<body bgcolor=white><h2>Here's the latest picture</h2>

 

<font color=red>

<?=

$errmsg

?>

</font>

 

 

<img src=?gim=1 width=144><br>

 

<?=

$title

?>

 

 

 

 

 

 

 

<hr>

<h2>Please upload a new picture and title</h2>

<form enctype=multipart/form-data method=post>

<input type=hidden name=MAX_FILE_SIZE value=150000>

<input type=hidden name=completed value=1>

IMAGE: <input type=file name=imagefile><br>

NAME: <input name=whatsit><br>

PRESS: <input type=submit></form><br>

<hr>

 

 

 

</body>

</html>

 

 

-reply by Binu K James


alex1985

Thanks. I need to associate with some another file. So, when I create that file, I let you know, just I will create another topic.


majklisko

maybe my solution will be helpful

at first create a folder 'images_full'
create an upload script:

<html><head><title>Upload foto</title></head><body><? if($img): $date=date("Y-m-d"); copy($img,"images_full/".$img_name); list($width,$height)=getimagesize("images_full/".$img_name); $insert=mysql_query("insert into $tabulka(image,descript,date,width,height) values('$img_name','$_POST[obr_popis]','$date','$width','$height')"); ?><img style="visibility:hidden;" src="th2.php?f=<? echo $img_name;?>&width=110&height=80&u=images_small" /><div><table border="0" cellspacing="0" cellpadding="0"><tr><td>Foto: </td><td><form method="post" enctype="multipart/form-data" onsubmit="" ><input size="10" type=file name="img" accept="image/*" /></td></tr><tr><td><input type="submit" value="vloz" /></td></tr></form></table></div></body></html>

the script uses another script th2.php to change the size of the image (u can select the maximal width and height) and save it, even the full size image is saved in 'images_full' folder :

<?header ("Content-type: image/jpeg");//vygeneruje thumbnailif(!$_GET[width]||!$_GET[height]):$new_width=133;//rozmery do ktorych sa ma obrazok zmestit$new_height=100;else:$new_width=$_GET[width];$new_height=$_GET[height];endif;$nasobic=$new_width/$new_height; $filename="images_full/".$_GET[f]; $path=$_GET[u]."/".$_GET[f]; $type=substr($filename,strpos($filename,'.')+1,strlen($filename)-strpos($filename,'.')); if ($type=="jpg"||$type=="JPG"){ $obrazok =imagecreatefromjpeg($filename); } elseif($type=="gif"||$type=="GIF"){ $obrazok =imagecreatefromgif($filename); } elseif($type=="png"||$type=="PNG"){ $obrazok =imagecreatefrompng($filename); } list($width,$height)=getimagesize($filename); if($width>$height*$nasobic)://vypocet rozmerov $new_height=round($height*$new_width/$width,0); else: $new_width=round($width*$new_height/$height,0); endif; $obr=imagecreatetruecolor ($new_width,$new_height); imagecopyresampled($obr, $obrazok,0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($obr,$path,100);?>

save this code to th2.php

alex1985

That looks really good, I should try it. Thanks