Jump to content

upload image


bakbai

Recommended Posts

please i need help, i got this code tried to run but i get this error

'Notice: Undefined index: image in \upload.php on line 10

 

Notice: Undefined index: image in \upload.php on line 11

 

Notice: Undefined index: image in \upload.php on line 14

', can any one pls help me?

 

the code below

the upload file

<?php

/********************************************************************************************************************************

PHPAsks.com

Developed by Asif Khalyani

Email : asif.khalyani@msn.com

 

********************************************************************************************************************************/

 

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

imgdiv.removeChild(image);

 

var image_new = par.createElement('img');

image_new.src = 'resize.php?pic=<?=$oname?>';

image_new.className = 'loaded';

 

imgdiv.appendChild(image_new);

 

var bre = par.createElement('br');

imgdiv.appendChild(bre);

 

var myLink1 = par.createElement('a');

myLink1.href = "#";

myLink1.className = "blacklink";

myLink1.onclick=function(e){alert('x'+' Y: '+'usrname');}

myLink1.appendChild(par.createTextNode('Remove'));

imgdiv.appendChild(myLink1);

 

var oNewP = par.createElement('span');

var oText = par.createTextNode("  ");

  oNewP.appendChild(oText);

  imgdiv.appendChild(oNewP);

 

</script></head>

</html>

<?php

exit();

}

?><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')[num];

iframe.className = 'hidden';

 

// create new iframe

var new_iframe = par.createElement('iframe');

new_iframe.src = 'upload.php';

new_iframe.frameBorder = '0';

par.getElementById('iframe').appendChild(new_iframe);

 

// add image progress

var images = par.getElementById('images1');

var new_div = par.createElement('div');

var new_img = par.createElement('img');

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

}

</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> the html file below

<?php

/********************************************************************************************************************************

PHPAsks.com

Developed by Asif Khalyani

Email : asif.khalyani@msn.com

 

********************************************************************************************************************************/

?>

<html>

<head>

<title>Asynchronous image file upload without AJAX | PHPasks.com</title>

<style>

iframe {border-width: 0px;height: 600px;width: 400px;}

iframe.hidden {visibility: hidden;width:0px;height:0px;}

#main1 {overflow: hidden;margin: auto;width: 90%;height: 420px;border-style: solid;border-width: 1px;background-color: white;}

#images1 {width: 95%;height: auto;margin: 20px;}

#images1 div {margin: 10px;width: 130px;height: 130px;border-style: solid;border-width: 2px;border-color: #DEDFDE;float: left;overflow: hidden;}

#images1 div:hover {border-color: #D8F18C;}

#images1 img.load { margin-top:20px;}

.blacklink:link, .blacklink:alink, .blacklink:vlink, .blacklink:hover{color:#000000}

a.redlink{color: #96001C; text-decoration: none}

a:hover.redlink{color: #96001C; text-decoration: underline}

</style>

</head>

<body>

<table width="600" align="center" cellpadding="0" cellspacing="0" border="0">

<Tr><td><h1>PHPAsks.com</h1></td></Tr>

<Tr>

<td align="center" valign="middle">

<div id="main1">

<div id="iframe">

<iframe src="upload.php" frameborder="0"></iframe>

</div>

<div id="images1">

</div>

</div>

<div id="myDivLink"></div>

</td>

</Tr>

    <tr>

    <Td align="center">

    Power by <a href="http://www.phpasks.com" class="redlink">PHPAsks.com</a>

        </Td>

    </tr>

</table>

</body>

</html>

 

the resize file

 

<?php

/********************************************************************************************************************************

PHPAsks.com

Developed by Asif Khalyani

Email : asif.khalyani@msn.com

 

********************************************************************************************************************************/

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

}

}

?>

 

Link to comment
Share on other sites

If you browsed directly to that file or the code in the file is being executed unconditionally, then it is because $_FILES['image'] does not exist at that point in time. If you however reached that file by submitting a proper form, then it either means that uploads are not enabled on your server or you exceeded the post_max_size setting.

 

We cannot really tell from the mess of code you posted what each piece is or even which piece the posted errors belong with. Please edit or repost your code with the contents of each file between

[/b]your code here[b]

tags and please identify the file name of each piece of code.

 

 

Link to comment
Share on other sites

thank you very much for you response and correction. there are three files here and a folder, the first is called index_image.php, the second one is the resize.php, then the uploade.php and finally we have the folder called upload. the index_image/php call the upload.php wirh an iframe

 

here are the code in that order

 <?php
/******************************************************************************************************************************** 
PHPAsks.com 
Developed by Asif Khalyani 
Email : asif.khalyani@msn.com

********************************************************************************************************************************/
?>
<html>
<head>
<title>Asynchronous image file upload without AJAX | PHPasks.com</title>
<style>
iframe {border-width: 0px;height: 600px;width: 400px;}
iframe.hidden {visibility: hidden;width:0px;height:0px;}
#main1 {overflow: hidden;margin: auto;width: 90%;height: 420px;border-style: solid;border-width: 1px;background-color: white;}
#images1 {width: 95%;height: auto;margin: 20px;}
#images1 div {margin: 10px;width: 130px;height: 130px;border-style: solid;border-width: 2px;border-color: #DEDFDE;float: left;overflow: hidden;}
#images1 div:hover {border-color: #D8F18C;}
#images1 img.load { margin-top:20px;}
.blacklink:link, .blacklink:alink, .blacklink:vlink, .blacklink:hover{color:#000000}
a.redlink{color: #96001C; text-decoration: none}
a:hover.redlink{color: #96001C; text-decoration: underline}
</style>
</head>
<body>
<table width="600" align="center" cellpadding="0" cellspacing="0" border="0">
<Tr><td><h1>PHPAsks.com</h1></td></Tr>
<Tr>
	<td align="center" valign="middle">
	<div id="main1">
		<div id="iframe">
		<iframe src="upload.php" frameborder="0"></iframe>
		</div>
		<div id="images1">
		</div>
	</div>
	<div id="myDivLink"></div>
	</td>
</Tr>
    <tr>
    	<Td align="center">
    	Power by <a href="http://www.phpasks.com" class="redlink">PHPAsks.com</a>
        </Td>
    </tr>
</table>	
</body>
</html>

 

<?php
/******************************************************************************************************************************** 
PHPAsks.com 
Developed by Asif Khalyani 
Email : asif.khalyani@msn.com

********************************************************************************************************************************/
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); 
}
}
?>

 


<?php
/******************************************************************************************************************************** 
PHPAsks.com 
Developed by Asif Khalyani 
Email : asif.khalyani@msn.com

********************************************************************************************************************************/

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];
		imgdiv.removeChild(image);

		var image_new = par.createElement('img');
		image_new.src = 'resize.php?pic=<?=$oname?>';
		image_new.className = 'loaded';

		imgdiv.appendChild(image_new);

		var bre	=	par.createElement('br');
		imgdiv.appendChild(bre);

		var myLink1 = par.createElement('a');
		myLink1.href = "#";
		myLink1.className = "blacklink";
		myLink1.onclick=function(e){alert('x'+' Y: '+'usrname');} 
		myLink1.appendChild(par.createTextNode('Remove')); 
		imgdiv.appendChild(myLink1);

		var oNewP = par.createElement('span');
		var oText = par.createTextNode("  ");
		  oNewP.appendChild(oText);
		  imgdiv.appendChild(oNewP);

		</script></head>
		</html>
		<?php
		exit();
	}	
?><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')[num];
iframe.className = 'hidden';

// create new iframe
var new_iframe = par.createElement('iframe');
new_iframe.src = 'upload.php';
new_iframe.frameBorder = '0';
par.getElementById('iframe').appendChild(new_iframe);

// add image progress
var images = par.getElementById('images1');
var new_div = par.createElement('div');
var new_img = par.createElement('img');
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);
}
</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>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.