4 Replies Latest reply on Feb 4, 2013 10:18 AM by monkeybreadsoftware

    Issue with Insert from URL

    HershHiltonHead

      I have a client who wants to move over 300K documents (PDF, xlsx, docx) from their onsite director(ies) to the new FM 12 solution I am designing for them. We are switching from a Ruby on Rails solution to full FM 12.

       

      When I script to grab the PDF documents in the Web Viewer - it requires a Login and Password. I have those from the client, but the outside vendor (the Ruby on Rail group) is not very helpful as they know the transition is being made. Due to the high count of documents involved I plan on doing these inserts "on the fly" when the new system calls an old record that has one or more PDF/xlsx/etc files linked to that record.

       

      Is there a simple way to pass the login and password via a script when it pings the URL?

       

      They sent me the following code:

       

      "

      <?
      $credentials = "username:password";
      $attachment_id = $_GET["attachment_id"];
      $filename = $_GET["filename"];

      $url = {removed by me due to NDA constraints} ;
      $page = "/attachments/$attachment_id/download";
      $headers = array(
      "GET ".$page." HTTP/1.1",
      "Accept: text/html,*/*",
      "Cache-Control: no-cache",
      "Pragma: no-cache",
      "Authorization: Basic " . base64_encode($credentials)
      );
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_TIMEOUT, '60');
      $content = curl_exec($ch);
      $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);

      if ($httpCode == 200) {
      $fp = fopen($filename, "w");
      fwrite($fp, $content);
      fclose($fp);
      print $httpCode . " File downloaded Ok<br/>";
      print "<img src='$filename'/>";
      } else {
      print $httpCode . " Error";
      }

      ?>

       

      Any help would be welcomed!

       

      Thanks in Advance

      Mark Hershinger

      SCSFileMaker