943,879 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1109
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 22nd, 2009
0

Dynamic path Function calling Error?

Expand Post »
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...

PHP Syntax (Toggle Plain Text)
  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:

PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 7
Junior Poster
sarithak is offline Offline
183 posts
since Aug 2008
Sep 22nd, 2009
0

Re: Dynamic path Function calling Error?

Id write this line of code as

php Syntax (Toggle Plain Text)
  1. createthumb($dir1,$dir.'/thumbs/'.$photo1,100,100);

Give that a try.
Reputation Points: 15
Solved Threads: 17
Junior Poster
phper is offline Offline
189 posts
since Nov 2006
Sep 22nd, 2009
0

Re: Dynamic path Function calling Error?

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++";
Reputation Points: 21
Solved Threads: 15
Junior Poster in Training
wilch is offline Offline
76 posts
since Aug 2007
Sep 22nd, 2009
0

Re: Dynamic path Function calling Error?

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++";
Reputation Points: 21
Solved Threads: 15
Junior Poster in Training
wilch is offline Offline
76 posts
since Aug 2007
Sep 22nd, 2009
0

Re: Dynamic path Function calling Error?

Your issue is your using single quotes ' instead of double quotes " as a string with a variable in it.
on line 48 you have:
PHP Syntax (Toggle Plain Text)
  1. createthumb('$dir1','$dir/thumbs/$photo1',100,100);//Not working(problem here only)

Try:
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 26
Solved Threads: 12
Junior Poster in Training
kylegetson is offline Offline
89 posts
since Sep 2009
Oct 19th, 2009
0
Re: Dynamic path Function calling Error?
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
Reputation Points: 10
Solved Threads: 7
Junior Poster
sarithak is offline Offline
183 posts
since Aug 2008
Oct 19th, 2009
0
Re: Dynamic path Function calling Error?
Thanks for sharing your ideas it can help me a lot...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chyssa is offline Offline
2 posts
since Oct 2009
Oct 20th, 2009
0
Re: Dynamic path Function calling Error?
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
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Oct 20th, 2009
0
Re: Dynamic path Function calling Error?
Click to Expand / Collapse  Quote originally posted by network18 ...
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...


PHP Syntax (Toggle Plain Text)
  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....
Reputation Points: 10
Solved Threads: 7
Junior Poster
sarithak is offline Offline
183 posts
since Aug 2008
Oct 20th, 2009
0
Re: Dynamic path Function calling Error?
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.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to echo html code in php echo
Next Thread in PHP Forum Timeline: find county using ip address





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC