Dynamic path Function calling Error?

Reply

Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster

Dynamic path Function calling Error?

 
0
  #1
Sep 22nd, 2009
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...

  1. function createthumb($name,$filename,$new_w,$new_h){
  2. $system=explode('.',$name);
  3. if (preg_match('/jpg|jpeg/',$system[1])){
  4. $src_img=imagecreatefromjpeg($name);
  5. }
  6. if (preg_match('/png/',$system[1])){
  7. $src_img=imagecreatefrompng($name);
  8. }
  9.  
  10. $old_x=imageSX($src_img);
  11. $old_y=imageSY($src_img);
  12. if ($old_x > $old_y) {
  13. $thumb_w=$new_w;
  14. $thumb_h=$old_y*($new_h/$old_x);
  15. }
  16. if ($old_x < $old_y) {
  17. $thumb_w=$old_x*($new_w/$old_y);
  18. $thumb_h=$new_h;
  19. }
  20. if ($old_x == $old_y) {
  21. $thumb_w=$new_w;
  22. $thumb_h=$new_h;
  23. }
  24. $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  25. imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
  26.  
  27. if (preg_match("/png/",$system[1]))
  28. {
  29. imagepng($dst_img,$filename);
  30. } else {
  31. imagejpeg($dst_img,$filename);
  32. }
  33. imagedestroy($dst_img);
  34. imagedestroy($src_img);
  35. }
  36.  
  37. $photo1=mysql_real_escape_string($_FILES['photo1']['name']);
  38. $tphoto1=mysql_real_escape_string($_FILES['photo1']['tmp_name']);
  39.  
  40. $dir="../../chillzone/citybuzz/$category/$dirid";
  41. if(!file_exists($dir))
  42. mkdir($dir)or die("Filename all ready exits");
  43. $dir1="$dir"."/"."$photo1" ; //working....
  44. if($photo1!=""){move_uploaded_file($_FILES['photo1']['tmp_name'], $dir1);}
  45.  
  46. createthumb('img5.jpg','thumbs/img5.jpg',100,100);//working....
  47.  
  48. createthumb('$dir1','$dir/thumbs/$photo1',100,100);//Not working(problem here only)

It displays errors:

  1. Notice: Undefined variable: src_img in C:\wamp\www\vvvv.com\admin\thumb.php on line 12
  2.  
  3. Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 12
  4.  
  5. Notice: Undefined variable: src_img in C:\wamp\www\aaa.com\admin\thumb.php on line 13
  6.  
  7. Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 13
  8.  
  9. Notice: Undefined variable: src_img in C:\wamp\www\aaa.com\admin\thumb.php on line 27
  10.  
  11. Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 27
  12.  
  13. Notice: Undefined variable: src_img in C:\wamp\www\aaa.com\admin\thumb.php on line 36
  14.  
  15. Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\vvvv.com\admin\thumb.php on line 36
Last edited by sarithak; Sep 22nd, 2009 at 7:58 am.
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 187
Reputation: phper is an unknown quantity at this point 
Solved Threads: 15
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: Dynamic path Function calling Error?

 
0
  #2
Sep 22nd, 2009
Id write this line of code as

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

Give that a try.
If my post is useful please add to my reputation.
Thanks.

Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 55
Reputation: wilch is an unknown quantity at this point 
Solved Threads: 9
wilch wilch is offline Offline
Junior Poster in Training

Re: Dynamic path Function calling Error?

 
0
  #3
Sep 22nd, 2009
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++";
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 55
Reputation: wilch is an unknown quantity at this point 
Solved Threads: 9
wilch wilch is offline Offline
Junior Poster in Training

Re: Dynamic path Function calling Error?

 
0
  #4
Sep 22nd, 2009
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++";
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 62
Reputation: kylegetson is an unknown quantity at this point 
Solved Threads: 9
kylegetson's Avatar
kylegetson kylegetson is offline Offline
Junior Poster in Training

Re: Dynamic path Function calling Error?

 
0
  #5
Sep 22nd, 2009
Your issue is your using single quotes ' instead of double quotes " as a string with a variable in it.
on line 48 you have:
  1. createthumb('$dir1','$dir/thumbs/$photo1',100,100);//Not working(problem here only)

Try:
  1. 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.
Last edited by kylegetson; Sep 22nd, 2009 at 11:52 pm. Reason: typo
Don't pay data charges. txtFeeder.com is a free way to read the web on your mobile, and avoid data charges! **Now txtFeeder has a wireless note feature! Make notes on the go!
-Kyle Getson
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster
 
0
  #6
Oct 19th, 2009
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
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: chyssa is an unknown quantity at this point 
Solved Threads: 0
chyssa chyssa is offline Offline
Newbie Poster
 
0
  #7
Oct 19th, 2009
Thanks for sharing your ideas it can help me a lot...
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #8
Oct 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster
 
0
  #9
Oct 20th, 2009
Originally Posted by network18 View Post
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...


  1.  
  2. $dir="../../dir/sub/$category/$dirid";
  3. if(!file_exists($dir))
  4. mkdir($dir)or die("Filename all ready exits");
  5. $tdir="../../dir/sub/$category/$dirid/thumbs";
  6. if(!file_exists($tdir))
  7. mkdir($tdir)or die("Filename all ready exits");
  8. //$dir1="$dir"."/"."$photo1" ;
  9. //$dir2="$dir"."/"."$photo2" ;
  10. //$dir3="$dir"."/"."$photo3" ;
  11. //$dir4="$dir"."/"."$photo4" ;
  12.  
  13. $dir1="$dir/$photo1" ;
  14. $dir2="$dir/$photo2" ;
  15. $dir3="$dir/$photo3" ;
  16. $dir4="$dir/$photo4" ;
  17.  
  18. if($photo1!=""){move_uploaded_file($_FILES['photo1']['tmp_name'], $dir1);
  19. createthumb("$dir1",'$dir/thumbs/$photo1',100,100);
  20. }


It creates Blank thumnail image...no errors....
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #10
Oct 20th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC