Jump to content

'<img src=" tag and $var$


phpfingers

Recommended Posts

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][/img][/img][/img]

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

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

 

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.