Jump to content
xisto Community

Image Upload ??

Recommended Posts

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.


Share this post

Link to post
Share on other sites

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





// Connect to database


$errmsg = "";

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

$errmsg = "Cannot connect to database";




// 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)




// 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.


$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 ();






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

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


<font color=red>







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













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









-reply by Binu K James

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.