doujianzhi3358 2011-04-30 01:56
浏览 44
已采纳

如何在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 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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误