3

我编写了一个脚本,可以在现有的法律案件案卷中搜索诸如“干预动议”和“强制动议”之类的内容。如果正则表达式返回 true,那么它会查看是否有在线文档的扫描图像供公众使用。该图像是 TIFF 文件,但不是普通的 tiff 文件。这是我试图复制到我自己的服务器的示例的链接。

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

如果您只尝试查看http://www.oscn.net/applications/oscn/getimage.tif ,则会出现以下错误

它是一个 TIFF 文件,但是是动态的。我使用了 fopen()、CURL 等但没有成功。我已经将这些类型的函数与来自随机站点的 JPG 图像一起使用,只是为了检查以确保我的服务器允许这种类型的东西并且它有效。

我没有在服务器上安装 PDFlib(我检查了 PEAR 并且它在那里也不可用,尽管我不能 100% 确定它会在哪里。)我的主机使用 cPanel。服务器正在运行 Apache。我不确定在哪里可以找到解决这个问题的方法。

我见过一些使用 PDFlib 的解决方案,但每个解决方案都抓取了一个普通的 TIFF 图像,而不是动态创建的。我的想法是,如果我可以让图像数据流式传输并不重要,我不应该能够使用 fopen() 并将该数据写入或缓冲到我自己的 .tif 文件中吗?

感谢您的任何意见和感恩节快乐!

更新:问题不在于 CURL,而在于我抓取传递给 CURL 的 URL。当我将 $url 打印到屏幕上时,它看起来正确,但事实并非如此。某处 & 变成了 &,然后抛出 CURL,因为它正在获取一个无效的 URL(至少根据 TIF 文件所在的远程服务器是无效的)。

对于那些后来发现它的人,这里是完美运行的脚本。

//*******************************************************************************
$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...\n";
$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.\n";
  }
}else{
  print "Unable to fetch file.\n";
}

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

贾罗德

4

1 回答 1

0

对于那些后来发现它的人,这里是完美运行的脚本。

//*******************************************************************************
$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...\n";
$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.\n";
  }
}else{
  print "Unable to fetch file.\n";
}

print "Done.\n";
exit(0);
//*******************************************************************************
于 2019-08-14T02:41:30.183 回答