duanlou2917 2012-11-22 07:34
浏览 56
已采纳

PHP Copy从远程服务器动态创建TIFF图像

I've written a script that searches through exiting legal case dockets for things like "motion to intervene" and "motion to compel". If the regular expression returns true, then it looks to see if there is a scanned image of the document online for public use. That image is a TIFF file, but not an ordinary tiff file. Here is a link to an example of what I'm trying to copy to my own server.

http://www.oscn.net/applications/oscn/getimage.tif?submitted=true&casemasterid=2565129&db=OKLAHOMA&barcode=1012443256

Here is the error you get if you only try to look at the http://www.oscn.net/applications/oscn/getimage.tif

It is a TIFF file but dynamic. I've used the fopen(), CURL, etc without success. I've used these types of functions with JPG images from random sites just to check to make sure that my server allowed this type of stuff and it worked.

I don't have PDFlib installed on the server (I checked the PEAR and it's not available there either, though I'm not 100% sure that is where it would be.) My host uses cPanel. The server is running Apache. I'm not sure where else to look for a solution to this problem.

I've seen some solutions that used PDFlib but each of those grabbed a normal TIFF image, not one that was dynamically created. My thought though is that it shouldn't matter if I can get the image data to stream, shouldn't I be able to use fopen() and write or buffer that data into my own .tif file?

Thanks for any input and Happy Thanksgiving!

UPDATE: The issue wasn't with CURL, it was with the URL I scraped to pass to CURL. When I printed the $url to the screen, it looked right, but it wasn't. Somewhere & was turned into &, which then threw off CURL because it was fetching an invalid URL (invalid at least according to the remote server where the TIF file is).

For those of you finding this later, here is the script that works perfectly.

//*******************************************************************************
$url = 'http://www.oscn.net/applications/oscn/getimage.tif"
$url .= '?submitted=true&casemasterid=2565129&db=OKLAHOMA&barcode=1016063497';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // set the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get the transfer as a string, rather than output it directly

print "Attempting to fetch file...
";
$img = curl_exec($ch); // get the image

//I used the time() so that in testing I would know when a new file was created rather than always overwriting the old file. This will be changed for final version
if($img){
  $fh = fopen('oscn_docs/' . time(). '.tif', 'w'); // this will simply overwrite the file. If that's not what you want to do, you'll have to change the 'w' argument!
  if($fh){
    $byteswritten = fwrite($fh, $img);
    fclose($fh);
  }else{
    print "Unable to open file.
";
  }
}else{
  print "Unable to fetch file.
";
}

print "Done.
";
exit(0);
//*******************************************************************************

jarod

  • 写回答

1条回答 默认 最新

  • dtu11716 2019-08-14 02:41
    关注

    For those of you finding this later, here is the script that works perfectly.

    //*******************************************************************************
    $url = 'http://www.oscn.net/applications/oscn/getimage.tif"
    $url .= '?submitted=true&casemasterid=2565129&db=OKLAHOMA&barcode=1016063497';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url); // set the url
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get the transfer as a string, rather than output it directly
    
    print "Attempting to fetch file...
    ";
    $img = curl_exec($ch); // get the image
    
    //I used the time() so that in testing I would know when a new file was created rather than always overwriting the old file. This will be changed for final version
    if($img){
      $fh = fopen('oscn_docs/' . time(). '.tif', 'w'); // this will simply overwrite the file. If that's not what you want to do, you'll have to change the 'w' argument!
      if($fh){
        $byteswritten = fwrite($fh, $img);
        fclose($fh);
      }else{
        print "Unable to open file.
    ";
      }
    }else{
      print "Unable to fetch file.
    ";
    }
    
    print "Done.
    ";
    exit(0);
    //*******************************************************************************
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成
  • ¥15 HC32L176调试了一个通过TIMER5+DMA驱动WS2812B
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!