| | |
Dynamic path Function calling Error?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 159
Reputation:
Solved Threads: 6
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...
It displays errors:
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)
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:
PHP Syntax (Toggle Plain Text)
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
Last edited by sarithak; Sep 22nd, 2009 at 7:58 am.
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Keep Smiling....Never Depress
Id write this line of code as
Give that a try.
php Syntax (Toggle Plain Text)
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
Thanks.
Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Your issue is your using single quotes ' instead of double quotes " as a string with a variable in it.
on line 48 you have:
Try:
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.
on line 48 you have:
PHP Syntax (Toggle Plain Text)
createthumb('$dir1','$dir/thumbs/$photo1',100,100);//Not working(problem here only)
Try:
PHP Syntax (Toggle Plain Text)
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
-Kyle Getson
•
•
Join Date: Aug 2008
Posts: 159
Reputation:
Solved Threads: 6
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
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
Keep Smiling....Never Depress
•
•
Join Date: Aug 2008
Posts: 159
Reputation:
Solved Threads: 6
0
#9 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
hey ..
Thanks...
this is my code...
PHP Syntax (Toggle Plain Text)
$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....
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Keep Smiling....Never Depress
![]() |
Similar Threads
- help on homework function error (C++)
- C++ function call error (C++)
- function not declared error (C++)
- Function calling (C)
- Recursive retrieve function calling getName() (C++)
- problem with redirecting error from function (Shell Scripting)
- help with creating and calling a function (C++)
- function takes 0 arguments error - probably a dumb question (C++)
- how to call a function from one file to another file (Shell Scripting)
- Wierd Error message. (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: How to echo html code in php echo
- Next Thread: find county using ip address
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl data database date directory display download dynamic echo email error file files folder foreach form forms function functions google href htaccess html httppost image include insert integration ip java javascript joomla limit link links login loop mail md5 menu mlm mod_rewrite multiple mysql mysql_real_escape_string oop parse paypal pdf php problem query radio random recursion regex remote replace script search server session sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video volume votedown web xml youtube





