Hi..
I am using downloaded code from google
it create frame when we upload image.
i am modified that code ..
I want like when uploaded new image
1> previous image is deleted or new image is overload on previous image in Same frame

but problem is when new image upload it going in old frame i.e. in 0ne frame i got 2 images previous image not deleted. and one new frames creates.
and so on no of images

So how to solve problem??

upload.php

<?php

sleep(2);
	$ftmp = $_FILES['image']['tmp_name'];
	$oname = $_FILES['image']['name'];
	
	$extenssion = strstr($oname, ".");
	$fname = 'upload/'.$_FILES['image']['name'];
		if(move_uploaded_file($ftmp, $fname)){
			?>
			<html><head><script>
			var par = window.parent.document;
			var images = par.getElementById('images1');
			var imgdiv = images.getElementsByTagName('div')[<?=(int)$_POST['imgnum']?>];
			var image = imgdiv.getElementsByTagName('img')[0];
			
			
			var image_new = par.createElement('img');
			image_new.src = 'resize.php?pic=<?=$oname?>';
			image_new.className = 'loaded';
			
			imgdiv.appendChild(image_new);
			
								
			

			</script></head>
			</html>
			<?php
			
		}	
?><html><head>
<script language="javascript">
function upload(){
	// hide old iframe
	var par = window.parent.document;
	//var num = par.getElementsByTagName('iframe').length - 1;
	var iframe = par.getElementsByTagName('iframe');
	iframe.className = 'hidden';
	
	// create new iframe
	var new_iframe = par.createElement('iframe');
	new_iframe.src = 'upload.php';
	new_iframe.frameBorder = '0';
	par.getElementById('iframe');
	
	// add image progress
	var images = par.getElementById('images1');
	var new_div = par.createElement('div');
	var new_img = par.createElement('images1');
	new_img.src = '/images/indicator.gif';
	new_img.className = 'load';
	new_div.appendChild(new_img);
	
	images.appendChild(new_div);


	//var imgnum = images.getElementsByTagName('div').length - 1;
	//document.iform.imgnum.value = imgnum;
	setTimeout(document.iform.submit(),5000);
	upload();
}
</script>
<style>
#file {
	width: 350px;
}
</style>
<head><body><center>
<form name="iform" action="" method="post" enctype="multipart/form-data">
<input id="file" type="file" name="image" onChange="upload()" />
<input type="hidden" name="imgnum" />
</form>
</center></html>

resize.php

<?php

if($_GET['pic']){
	$img = new img('upload/'.$_GET['pic']);
	$width	=	$_GET["width"];
	$height	=	$_GET["height"];
	$img->resize();
	$img->show();
}

class img {
	
	var $image = '';
	var $temp = '';
	
	function img($sourceFile){
		if(file_exists($sourceFile)){
			$this->image = ImageCreateFromJPEG($sourceFile);
		} else {
			$this->errorHandler();
		}
		return;
	}
	
	function resize($width = 100, $height = 100, $aspectradio = true){
		$o_wd = imagesx($this->image);
		$o_ht = imagesy($this->image);
		if(isset($aspectradio)&&$aspectradio) {
			$w = round($o_wd * $height / $o_ht);
			$h = round($o_ht * $width / $o_wd);
			if(($height-$h)<($width-$w)){
				$width =& $w;
			} else {
				$height =& $h;
			}
		}
		$this->temp = imageCreateTrueColor($width,$height);
		imageCopyResampled($this->temp, $this->image,
		0, 0, 0, 0, $width, $height, $o_wd, $o_ht);
		$this->sync();
		return;
	}
	
	function sync(){
		$this->image =& $this->temp;
		unset($this->temp);
		$this->temp = '';
		return;
	}
	
	function show(){
		$this->_sendHeader();
		ImageJPEG($this->image);
		return;
	}
	
	function _sendHeader(){
		header('Content-Type: image/jpeg');
	}
	
	function errorHandler(){
		echo "error";
		exit();
	}
	
	function store($file){
		ImageJPEG($this->image,$file);
		return;
	}
	
	function watermark($pngImage, $left = 0, $top = 0){
		ImageAlphaBlending($this->image, true);
		$layer = ImageCreateFromPNG($pngImage); 
		$logoW = ImageSX($layer); 
		$logoH = ImageSY($layer); 
		ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH); 
	}
}
?>

Just like when we click on Edit profile

And change photo....

How to do that???

i am creating this code for uploading image without click on submit button ...
also storing path of image in database....
when edit a profile i want to show that replace new image to old image ...
i think do some changes in script so it resolve problem
how to do that??

how to modified script that means ..
new_div.appendChild(new_img);

it appends with old image ...

any other method that remove older & replace with new??

This article has been dead for over six months. Start a new discussion instead.