php question
Results 1 to 6 of 6

Thread: php question

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    161

    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

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    735

    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>
    [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

  3. #3
    Just a Virtualized Geek MrLinus's Avatar
    Join Date
    Sep 2001
    Location
    Redondo Beach, CA
    Posts
    7,324
    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.

    =)
    Goodbye, Mittens (1992-2008). My pillow will be cold without your purring beside my head
    Extra! Extra! Get your FREE copy of Insight Newsletter||MsMittens' HomePage

  4. #4
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    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.

  5. #5
    Senior Member
    Join Date
    Mar 2002
    Posts
    502

    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>
    [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
    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
    Bleh.

  6. #6
    Senior Member
    Join Date
    Apr 2002
    Posts
    161
    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]<?php echo($_SERVER['PHP_SELF'].[/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
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides