-
February 19th, 2003, 03:20 AM
#1
Senior Member
php question
Is it possible to assign a variable to a file (in this case a pic) in php???
-----------------------------------------------------------------
<html>
<body>
<?php $num=4;
$i=10;
$res=$i*$num;
$foto=pic1.gif;
printf("resultado igual a $res
");
php?>
<center>
[img]<?$foto?>[/img]
</body>
</html>
-------------------------------------------------------------------------
The numerical variables are correctly displayed, but the picture is not shown at all, the picture is stored in the same dir as my .php file. I don't know what else to add so that the pic can be displayed.
thanks
-
February 19th, 2003, 12:21 PM
#2
Re: php question
Do you mean something like this?
PHP Code:
<?php
$foto="pic1.gif";
echo "resultado igual a 40 ");
echo "<img src=\"$foto\">";
?>
Originally posted here by johnnymier
Is it possible to assign a variable to a file (in this case a pic) in php???
-----------------------------------------------------------------
<html>
<body>
<?php $num=4;
$i=10;
$res=$i*$num;
$foto=pic1.gif;
printf("resultado igual a $res
");
php?>
<center>
</body>
</html>
-------------------------------------------------------------------------
The numerical variables are correctly displayed, but the picture is not shown at all, the picture is stored in the same dir as my .php file. I don't know what else to add so that the pic can be displayed.
thanks
-
February 19th, 2003, 12:22 PM
#3
As far as I know you cannot assign a picture as a variable. You can assign a file to a variable to manipulate it (add stuff, take stuff away, etc.) by using fopen() (I think that's it.. haven't personally used it). You might want to visit either phpfreaks.com or phpbuilder.com for some ideas as to how to take pictures out of a database like MySQL.
=)
-
February 19th, 2003, 12:31 PM
#4
You could always save the filename as a string, but I don't know if that's what you need...
As far as I can see, you use a picture to display some text? PHP has (limited) capability to draw or edit images itself. Look here: http://www.php.net/manual/en/ref.image.php
I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.
-
February 19th, 2003, 12:41 PM
#5
Re: php question
Originally posted here by johnnymier
Is it possible to assign a variable to a file (in this case a pic) in php???
-----------------------------------------------------------------
<html>
<body>
<?php $num=4;
$i=10;
$res=$i*$num;
$foto=pic1.gif;
printf("resultado igual a $res
");
php?>
<center>
</body>
</html>
-------------------------------------------------------------------------
The numerical variables are correctly displayed, but the picture is not shown at all, the picture is stored in the same dir as my .php file. I don't know what else to add so that the pic can be displayed.
thanks
PHP Code:
<?php
if ($_GET['mode'] == "image")
{
$image = implode("", file("pic1.gif"));
header('Content-Type: image/gif');
echo($image);
exit;
}
?>
<html>
<head>
<title>the pic</title>
</head>
<body>
Just some text
[img]<?php echo($_SERVER['PHP_SELF'].[/img]" />
</body>
</html>
That should work. If i'm right, IE doesnt require any GIF headers to be send to the browser for the echo to be displayed as an actual image, but im not sure.
EDIT: I misread your post. If you want the picture to be displayed, then you should quote your filename. In PHP, you have to quote anything that contains letters when assigning things to a variable. So,
$mypic = "pic1.gif";
should make your script work correctly. If this is what you are looking for, then I also recommend that you look at the PHP Manual, starting HERE >> http://www.php.net/manual/en/tutorial.php
-
February 19th, 2003, 05:47 PM
#6
Senior Member
Thanks Sickdwarf, your code worked:
PHP Code:
<?php
if ($_GET['mode'] == "image")
{
$image = implode("", file("pic1.gif"));
header('Content-Type: image/gif');
echo($image);
exit;
}
?>
<html>
<head>
<title>the pic</title>
</head>
<body>
Just some text
[img]http://www.antionline.com/[/img]" />
</body>
</html>
For my code, you were right, I needed to quote the file name and I forgot to add the equal sign here: [img]<?=$image?>[/img]
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|