954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dynamic path Function calling Error?

Hi frnds...

Here i am creating thumbnail image...the code is working fine...

The variables are not working calling funtion....if i give static path, its working fine...

incase of dynamic path it displays some errors,but image created..image with full black(no photo).......plz check the below code...

function createthumb($name,$filename,$new_w,$new_h){
	$system=explode('.',$name);
	if (preg_match('/jpg|jpeg/',$system[1])){
		$src_img=imagecreatefromjpeg($name);
	}
	if (preg_match('/png/',$system[1])){
		$src_img=imagecreatefrompng($name);
	}
		
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
	$thumb_w=$old_x*($new_w/$old_y);
	$thumb_h=$new_h;
}
if ($old_x == $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
	
if (preg_match("/png/",$system[1]))
{
	imagepng($dst_img,$filename); 
} else {
	imagejpeg($dst_img,$filename); 
}
imagedestroy($dst_img); 
imagedestroy($src_img); 
}

$photo1=mysql_real_escape_string($_FILES['photo1']['name']);
$tphoto1=mysql_real_escape_string($_FILES['photo1']['tmp_name']);

$dir="../../chillzone/citybuzz/$category/$dirid";
if(!file_exists($dir))
mkdir($dir)or die("Filename all ready exits");
$dir1="$dir"."/"."$photo1" ; //working....
if($photo1!=""){move_uploaded_file($_FILES['photo1']['tmp_name'], $dir1);}

createthumb('img5.jpg','thumbs/img5.jpg',100,100);//working....

createthumb('$dir1','$dir/thumbs/$photo1',100,100);//Not working(problem here only)


It displays errors:

Notice: Undefined variable: src_img in C:\wamp\www\vvvv.com\admin\thumb.php on line 12

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 12

Notice: Undefined variable: src_img in C:\wamp\www\aaa.com\admin\thumb.php on line 13

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 13

Notice: Undefined variable: src_img in C:\wamp\www\aaa.com\admin\thumb.php on line 27

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 27

Notice: Undefined variable: src_img in C:\wamp\www\aaa.com\admin\thumb.php on line 36

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 36
sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

Id write this line of code as

createthumb($dir1,$dir.'/thumbs/'.$photo1,100,100);


Give that a try.

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
 

well, if the problem is on line 48, the most sinister actors would be the 2 arguments '$dir1' AND '$dir/thumbs/$photo1'

- try outputting these strings before you call the function, and see what they contain.
e.g. echo "++$dir1++$dir/thumbs/$photo1++";

wilch
Junior Poster in Training
84 posts since Aug 2007
Reputation Points: 25
Solved Threads: 17
 

well, if the problem is on line 48, the most sinister actors would be the 2 arguments '$dir1' AND '$dir/thumbs/$photo1'

- try outputting these strings before you call the function, and see what they contain.
e.g. echo "++$dir1++$dir/thumbs/$photo1++";

wilch
Junior Poster in Training
84 posts since Aug 2007
Reputation Points: 25
Solved Threads: 17
 

Your issue is your using single quotes ' instead of double quotes " as a string with a variable in it.
on line 48 you have:

createthumb('$dir1','$dir/thumbs/$photo1',100,100);//Not working(problem here only)


Try:

createthumb("$dir1","$dir/thumbs/$photo1",100,100);//Not working(problem here only)


the problem is, that when you use single quotes '$myvar' will actually be the string $myvar instead of the variable myvar. PHP does not parse inside single quotes, only double quotes.

hope that helps.

kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12
 

Hi friends...

Thanks 4 ur suggestions...
the total path taking correctly...But instead of creating thumbnail image..it creates blank thumbnail image....

But when the path giving statically it create correct thumbnail image...plz check the above code....


Thanks in advance...

Saritha K

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

Thanks for sharing your ideas it can help me a lot...

chyssa
Newbie Poster
2 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

function createthumb() expect the first parameter to be image file name and i guess $filename is the directory path.
I think there is problem with you passing as $dir1, it seems to be made from $dir and some dir structure.Also what comes in $dirid is not been clear

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
function createthumb() expect the first parameter to be image file name and i guess $filename is the directory path. I think there is problem with you passing as $dir1, it seems to be made from $dir and some dir structure.Also what comes in $dirid is not been clear


hey ..

Thanks...

this is my code...

$dir="../../dir/sub/$category/$dirid";
if(!file_exists($dir))
mkdir($dir)or die("Filename all ready exits");
$tdir="../../dir/sub/$category/$dirid/thumbs";
if(!file_exists($tdir))
mkdir($tdir)or die("Filename all ready exits");
//$dir1="$dir"."/"."$photo1" ;
//$dir2="$dir"."/"."$photo2" ;
//$dir3="$dir"."/"."$photo3" ;
//$dir4="$dir"."/"."$photo4" ;

$dir1="$dir/$photo1" ;
$dir2="$dir/$photo2" ;
$dir3="$dir/$photo3" ;
$dir4="$dir/$photo4" ;

if($photo1!=""){move_uploaded_file($_FILES['photo1']['tmp_name'], $dir1);
createthumb("$dir1",'$dir/thumbs/$photo1',100,100);
}

It creates Blank thumnail image...no errors....

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

did you noticed that you checking with image type against jpeg/jpg and png, check which format image you passing, when blank thumbnail gets created.

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
did you noticed that you checking with image type against jpeg/jpg and png, check which format image you passing, when blank thumbnail gets created.


Hi...

here i m using same image for both static testing & dynamic...i.e JPEG.....

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You