phpfingers Posted November 23, 2007 Share Posted November 23, 2007 hi alll im new and learning php4 i hope you can help here is part of a simple code but to me it mighty difficult $b="test.jpg"; $a='<img src="/path/whatever/blah/">'; echo $a.$b; when i run the the i get this in the brower a square box here to the left of "test.ppp" the image is where it should be. so im realy puzzled see the pic the error as examplained above thanks pf[/img][/img][/img] [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 $b="test.jpg"; $a='<img src="/path/whatever/blah/">'; echo $a.$b; The result of $a.$b would be: <img src="/path/whatever/blah/">test.jpg Which is not valid HTML. You want: <img src="/path/whatever/blah/test.jpg"> Back to the drawing board wid ya! PhREEEk Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 sorry i took the wrong snapshot it should of said test.jpg so how do i get the image shown by using a varible instead ogf writing the actual static path PF Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 thanks PHP_PhREEEk my problem is that i have 100 images that i want to pull from the mysql database. i have written the rest of the code already. instead of me writing 100 static links what i want to do is use a varible with the img scr tag i hope you understand Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 What Phreek is saying is the way you have your code structured, your File Name is outside of the <img src> tag. You need to get your variable inside of that tag. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Well, you were very close... the dot (.) joins two things together so, $a = <img src="/path/whatever/blah/"> $b = test.jpg $a.$b = <img src="/path/whatever/blah/">test.jpg What you need to do is: <?php $b="test.jpg"; $a='<img src="/path/whatever/blah/'; $a .= $b $a .= '>"'; echo $a; That's a very simplistic approach to show you exactly what is going on each step of the way. There are more efficient ways of doing this, this is just an example. PhREEEk Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Easier way here: <?php $b="test.jpg"; $a="<img src=\"/path/whatever/blah/$b\">"; echo $a; Using double quotes when defining $a allows us to use $b directly. It also makes it necessary to escape (\) any literal double quotes, so src="/path/whatever/blah/$b" becomes src=\"/path/whatever/blah/$b\" PhREEEk Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 PHP_PhREEEk thanks for helping but now im really scratching my head. here is the code <?php $b="ebwmp-16-hh.jpg"; $a='<img src="/aoauth/images/'; $a .= $b; $a .= '>"'; echo $a; //------------------------------------------- $b="ebwmp-16-hh.jpg"; $a="<img src=\"/aoauth/images/$b\">"; echo $a; ?> when i run it i see nothing in the browser however if i put in the static address in browser then the image is shown http://www.blah.com/aoauth/images/ebwmp-16-hh.jpg i just dont get it. i dont think im that dumb im pretty ok with php the execption of handling graphics PF Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 This is assuming you are running this script from the webroot. You can try a absolute path instead: <?php $b="ebwmp-16-hh.jpg"; $a='<img src="http://www.blah.com/aoauth/images/'; $a .= $b; $a .= '>"'; echo $a; ?> Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Try removing the leading slash: <?php $b="ebwmp-16-hh.jpg"; $a="<img src=\"aoauth/images/$b\">"; echo $a; ?> PhREEEk Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 revraz thanks, yea that worked as expected it showed only the full path and filename . i cant believe its something this simply that is tripping me up . anyone else wants to try the img scr fear factor KH Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 PHP_PhREEEk thanks but no luck there either i tried 3 different browser cleared clean cookie and still the same nill PF Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 23, 2007 Share Posted November 23, 2007 try this <?php $b="ebwmp-16-hh.jpg"; $a= "<img src='http://www.blah.com/aoauth/images/{$b}'>"; echo $a; ?> Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Just for fun, let's do this... Run this code: <?php $b="ebwmp-16-hh.jpg"; $a="<img src=\"/aoauth/images/$b\">"; echo $a; ?> When the image does NOT appear, right click the red x and select Properties, which should show the path the browser tried to use to access the image. Post that, and also post the HTML source for me. While the absolute path will work every time, relative paths should work too... PhREEEk Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 revraz yea thanks $b="ebwmp-16-hh.jpg"; $a='<img src="http://www.blah.com/aoauth/images/'; $a .= $b; $a .= '>"'; echo $a; the above code was the ticket i really want to thank you all for helping me move past this point. i dont think that i would of figure out the concatenating part and so i am appreciative for the answers PF Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 sorry guys revraz did editi the text and by the time i got back, saw it, re-tried his new suggestion and tested then there was more response. its all good and im still amazed over the concatenating. it looks weird but it works Thanks again Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 im back, this time with clearer head yesterday i was looking at this problem till around 4am in the morning (before posting here). since then i have return to this problem in a more logical view so please help me out as this time ill show you exactly what im seeing. ok most of the scripts above do work but not when the same script is in my code block. for example. im new to php ¥ mysql (5 months) and being trying to battle my way through my learning site that i started from scratch. www.i3u.info/test/ the problem now you are on the site, on the right hand side under "The 10 latest ads" click "ss" the new page that you now see will have a broken image beside the words "Item Picture" these are the codes im using this code is part of a function that receives the picture name in $newimgname $newimgname="<img src=\"http://www.i3u.info/test/aoauth/images/$newimgname\">"; $query = "UPDATE ad_table SET snapshotthb ='$snappic', uploaded_pic ='$newimgname' WHERE username='$valid_user'"; $result = mysql_query($query); this is the output page (where the pic should be shown) <tr> <td width="331" height="2"></td> <td width="404" rowspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr valign="middle"> <td height="21" colspan="2" valign="top"><font color='#000000' size='2'><b>Item Picture</b></font></td> <td width="2"></td> </tr> <tr align="center" valign="middle"> <td width="400" height="300" valign="top"> <img src="/test/aoauth/images/fittedimg/ebwmp-1259-ss.jpg>" <-------------- the fault is there </td> <td width="2"> </td> <td> </td> </tr> i hope you still with me but heres what puzzling. some of the above examples that you guys provided did work.. i tried them all and settled with <?php $b="ebwmp-1259-ss.jpg"; $a="<img src=\"http://www.i3u.info/test/aoauth/images/$b"\"> ?> i placed the above code in a php file and it does work you can see it here in action at http://i3u.info/test/testpad.php and here is the output source for testpad here <img src="http://www.i3u.info/test/aoauth/images/ebwmp-1259-ss.jpg"> now here is my problem. for some strange reason when the above code is on its own it rns perfectly. but when i put it the php function it does not work at all. compare the two lines below output when code is on its own here <img src="http://www.i3u.info/test/aoauth/images/ebwmp-1259-ss.jpg"> when the script is run from a function <img src="/test/aoauth/images/fittedimg/ebwmp-1259-ss.jpg>" <-------------- the fault is there have you notice that what should of been a "> has turned into a >" ? please help me out. i have been through some learning curve while building my site but this IMG SRC= tag is gonna give me a nothing but headache. i have laid it all out for you and so i only wish that i can be help. thank you for your time and understanding PF Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 Repost the updated function. Quote Link to comment Share on other sites More sharing options...
phpfingers Posted November 23, 2007 Author Share Posted November 23, 2007 here is the full function it does a few tasks including inserting the newimage path/newimage to the db i also posted a pic of the testpad.php page so that you can see that the fault is >" changes to "> function readuploadfile($validuser,$ufname) { //get paths ready $uemail="me@yahoo.com"; $subject="a new picture waiting for validation"; $from_email_address="me@yahoo.com"; $pictouser="/home/hd19083/pictouser.txt"; $snappic='<img src="/test/images/snapshop.gif">'; //the small image on rct and rrt $temppic='<img src="/test/images/imageawv.gif">'; //the image used while uploaded image is being reviewed $write_data=" uploaded "; $udate=date("Y,m,d"); $write_data_marker="|"; $valid_user= $_SESSION['valid_user']; //now get the file from the uploaded section and match them to user $current_dir="/home/hd19083/public_html/test/aoauth/images"; $dir = opendir($current_dir); while ($filename = readdir($dir)) { //read all filenames in directory from root if (is_file($current_dir . '/' . $filename)) { //test to see if its found the uploaded file if so write it out to pic2user if ($filename == $ufname) { //get user id and create new file name $user_id=retuser_id(); //rename uploaded pic $newimgname='ebwmp-'.$user_id.'-'.$valid_user.'.jpg'; rename($current_dir.'/'.$filename,$current_dir.'/'.$newimgname); //write this to pic2user.txt eg........ 2007.11.20 test uploaded ipod.jpg| $fh=fopen($pictouser, "a+"); $write_it= fwrite($fh, $udate." ".$valid_user.$write_data.$filename.$write_data_marker); fwrite($fh, "\n"); fclose($fh); //now send a mail to me.. new pic to be verified $message="Today $udate, this user $valid_user $write_data $newimgname"; mail($uemail,$subject,$message,"FROM: $from_email_address"); //get ready the temp and pic icons. set the picflag to 1 this //should be removed only by resizer when the verified ad pic is //about to be visible. $newimgname="<img src=\"http://www.i3u.info/test/aoauth/images/$newimgname\">"; $query = "UPDATE ad_table SET snapshotthb ='$snappic', uploaded_pic ='$newimgname' WHERE username='$valid_user'"; $result = mysql_query($query); } } } return($newimgname); } [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.