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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题