Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP Problem

  • 03-03-2005 3:04pm
    #1
    Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭


    Basicly im embedding a URL in to a page that returns a dynamicaly created image (a map). This works very well from abrowser on a full PC.

    I do the same on a PDA and the sytem on the far end (that creates the map) claims not to support the PDA web browser... Thats a load of ****e because its just an image...

    So i wget the url and rename the resulting file to map.gif point the pda at map.gif and low and behold I get them map on screen. Great.

    Problem is I dynamically compose the link in PHP that creates the image every time the page is loaded so I need to get PHP to proxy the image for me each time so that the webserver on the far end dosnt moan about the browser.

    Can anyone help?


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Haven't really looked into it - but is it possible to get PHP to create the image and then write it to file?

    That is, you call a function createImage() which generates the image you're looking for, writes it to file, with a name corresponding to the SessionID or a timestamp or something (like map5666214684.gif) and returns that name. Then you just use this name in the <img> tag on your page.

    You'd need to regularly clear out the folder containing these images so it doesn't fill up.

    Is this exactly what you're asking can you do? :D

    {edit:
    This might help. It has a bit on writing images to disk at the bottom. }

    {Edit 2: Infact the imagegif() and imagejpeg() functions have a second parameter for the file location you wish to write the file to. It couldn't be simpler. :) }


  • Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭Rew


    Thx for that.

    Have it writing the image to a temp folder and its all working. Writing it to disk is a bit of a pain in the arse as the image is never required again once the page has loaded so I need to clean up the temporaty files in some way as well.

    Using imagegif() without a save path just throws up a laod a text on the screen.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Rew wrote:
    Thx for that.

    Have it writing the image to a temp folder and its all working. Writing it to disk is a bit of a pain in the arse as the image is never required again once the page has loaded so I need to clean up the temporaty files in some way as well.

    Using imagegif() without a save path just throws up a load a text on the screen.
    Yeah, when you specify imagegif() without a file path, it defaults to outputting it to the screen. (actually, defaults to the http file output stream, but you know what I mean)
    You may be able to create a routine for the file clearance, but it would add some overhead to the image script.

    One way I'd think of it, is you have a text file within the directory, that contains a timestamp, which is the last time that the directory was cleared out. Initially this would be zero, obviously.
    Each time you run the create image script, you check this file and if the stored timestamp is less than Now() - 3600 (i.e. more than one hour ago), you delete each file in the directory, created less than or equal to now() - 3600, then you update the text file with now().


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    What headers are you sending out with the dynamic image? PC browsers can be far more forgiving than handheld browsers where it comes to malformed or missing HTTP headers.


  • Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭Rew


    The dynamic image is served by a 3rd party so iv no controll over it. When you call the image directly in the PDA browser you get a message from the 3rd part saying they dont support the browser.

    I could clena the directory witha cron job as well using time stamps to make sure I dont delete one that's about to be used. It would be nice to do it wihout creating the file thats all.


  • Advertisement
  • Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭Rew


    For reference this is how the code looks at the min:
    $link1 = "URL of dynamic image";

    $im = ImageCreateFromGIF ($link1);

    imagegif($im,"/path/r/to/some/temp/dir/tmp.gif");

    echo "<img src=\"tmp/tmp.gif\">\n";

    I know this isnt scaleable beyone just me looking at the page but ill work on that next.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Rew wrote:
    The dynamic image is served by a 3rd party so iv no controll over it. When you call the image directly in the PDA browser you get a message from the 3rd part saying they dont support the browser.
    Can you not directly proxy the image so? (Probably what you were looking for originally :D)

    e.g.
    $link1 = "URL of dynamic image";
    $im = ImageCreateFromGIF($link1);
    
    
    Header("Content-Type: image/jpeg");
    
    imagegif($im);
    


  • Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭Rew


    Page has text on it as well but what I might be able to do is create a seperate script that gets the image and displays it then call that form the main page to display the image.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Rew wrote:
    Page has text on it as well but what I might be able to do is create a seperate script that gets the image and displays it then call that form the main page to display the image.
    Exactly.

    You can create a php file called map.php, for example. In your main php file, you call <img src="./map.php?var1=a&var2=b"> and then map.php takes the vars, passes them over to your third party site.....

    You get the drift.


  • Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭Rew


    Its working

    Have to change it to take variables via the url (its 2 seperate MySQL selects ATM) but works great. Pitty image rendering on Pocket PC is so crap...

    Thx a mil

    :)


  • Advertisement
  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Another alternative would be:
    [PHP]$s_imgURL = "URL of dynamic image";
    $fp = fopen($s_imgURL, "rb");
    while ($data = fread($fp, 4096)) $s_imgData .= $data;
    header("Content-Type: image/gif");
    header("Content-Disposition: inline");
    header("Content-Length: ".strlen($s_imgData));
    echo $s_imgData;[/PHP]
    Btw, is the image supposed to be a Giff or Jpeg?


  • Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭Rew


    Good question, honestly I dont know I took a chance on it being a gif, its a map generated from vector data and then anotated with a few bits.


Advertisement