doujianzhi3358
2011-04-30 01:56 阅读 42
已采纳

如何在PHP中命名和/或下载动态呈现图像以重定向到另一个页面

Ok, I have an API I use that holds a scene file in a dotnet project. I pass it params that adds images to a final image that is rendered out on a webpage. i.e. myserver/GetImage.ashx?param1=value1 which I use link to display an image that is dynamically rendered on my webpage. Value1 = myserver/images/myimage.jpg

My problem is I need to be able to take the result and run it back through the API, so value1 cannot equal myserver/GetImage.ashx?param1=myserver/images/myimage.jpg.

My question is, how can I redirect or store the first result in PHP as FinalRender.jpg to run it back through the API, so it would look like myserver/GetImage.ashx?FinalRender.jpg?

I am totally lost so any help would be very appreciated.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douchunjing6587 douchunjing6587 2011-05-07 22:26

    Ok, I figured it out.

    I created a session ID:

    $a = session_id();
    if(empty($a)) session_start();
    

    then I grabbed the API image by the HTML ID as shown below:

    $a = session_id();
    
    
    $api_url = 'imgtest2.php';  
    $dom = new DOMDocument();
    if (@$dom->loadHTMLFile($api_url)) { 
      $img_tag = $dom->getElementById('render'); 
      $src = $img_tag->getAttribute('src'); 
      $img_content = file_get_contents($src); 
      file_put_contents('user/' . $a . "/" . $a . '.jpg', $img_content);
    }
    
    点赞 评论 复制链接分享

相关推荐