automated upload with PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Poe

    #1

    automated upload with PHP

    I work for an animal hospital trying to use PHP to store an animal's
    dental x-rays to a file server.

    I can browse for the xray on the local desktop computer then click
    "Upload Image". This works fine. The doctors want fewer steps to
    follow. So, it was asked if I can configure the browser to load/submit
    the image 'xray.tif' each time they click "Upload Image" instead of
    the doctor/animal technician having to look for for dental x-ray
    image.

    Does PHP support such a feature to pull/load a file of the client's
    computer? My three PHP books aren't helping, but I am probably looking
    in the wrong direction.

    Thanks.

    Steve

  • shimmyshack

    #2
    Re: automated upload with PHP

    On 29 Mar, 17:38, "Steve Poe" <steve....@gmai l.comwrote:
    I work for an animal hospital trying to use PHP to store an animal's
    dental x-rays to a file server.
    >
    I can browse for the xray on the local desktop computer then click
    "Upload Image". This works fine. The doctors want fewer steps to
    follow. So, it was asked if I can configure the browser to load/submit
    the image 'xray.tif' each time they click "Upload Image" instead of
    the doctor/animal technician having to look for for dental x-ray
    image.
    >
    Does PHP support such a feature to pull/load a file of the client's
    computer? My three PHP books aren't helping, but I am probably looking
    in the wrong direction.
    >
    Thanks.
    >
    Steve
    sure, you can script on the client using what is called active
    scripting.
    its nice and familiar, so you would either
    1) have your script one once per day and upload any images not already
    uploaded from a set of folders
    2) configure explorer so you can right click and select upload image,
    your php script would be run in the bvackground with argument such as
    c:\path\to\php -r "%1"
    and it would do the rest.
    Why not use FTP if you are scripting this, as it will be nice and
    robust and can interact is a predicatable way with your fileserver -
    providing it can have an ftp serve running on it, like filezilla
    server.

    Comment

    • shimmyshack

      #3
      Re: automated upload with PHP

      On 29 Mar, 18:25, "shimmyshac k" <matt.fa...@gma il.comwrote:
      On 29 Mar, 17:38, "Steve Poe" <steve....@gmai l.comwrote:
      >
      >
      >
      I work for an animal hospital trying to use PHP to store an animal's
      dental x-rays to a file server.
      >
      I can browse for the xray on the local desktop computer then click
      "Upload Image". This works fine. The doctors want fewer steps to
      follow. So, it was asked if I can configure the browser to load/submit
      the image 'xray.tif' each time they click "Upload Image" instead of
      the doctor/animal technician having to look for for dental x-ray
      image.
      >
      Does PHP support such a feature to pull/load a file of the client's
      computer? My three PHP books aren't helping, but I am probably looking
      in the wrong direction.
      >
      Thanks.
      >
      Steve
      >
      sure, you can script on the client using what is called active
      scripting.
      its nice and familiar, so you would either
      1) have your script one once per day and upload any images not already
      uploaded from a set of folders
      2) configure explorer so you can right click and select upload image,
      your php script would be run in the bvackground with argument such as
      c:\path\to\php -r "%1"
      and it would do the rest.
      Why not use FTP if you are scripting this, as it will be nice and
      robust and can interact is a predicatable way with your fileserver -
      providing it can have an ftp serve running on it, like filezilla
      server.
      oops I should have added, that if you have a few computers you need to
      install this on you could use NSIS (Nullsoft Scriptable Install
      System) http://nsis.sourceforge.net/Main_Page to wrap up everything
      including the script that makes the right click functionality between
      tiffs and the php script, and distribute that.

      Comment

      • Steve Poe

        #4
        Re: automated upload with PHP

        sure, you can script on the client using what is called active
        scripting.
        its nice and familiar, so you would either
        1) have your script one once per day and upload any images not already
        uploaded from a set of folders
        2) configure explorer so you can right click and select upload image,
        your php script would be run in the bvackground with argument such as
        c:\path\to\php -r "%1"
        and it would do the rest.
        Why not use FTP if you are scripting this, as it will be nice and
        robust and can interact is a predicatable way with your fileserver -
        providing it can have an ftp serve running on it, like filezilla
        server.
        >
        oops I should have added, that if you have a few computers you need to
        install this on you could use NSIS (Nullsoft Scriptable Install
        System)http://nsis.sourceforge.net/Main_Pageto wrap up everything
        including the script that makes the right click functionality between
        tiffs and the php script, and distribute that.

        Thanks for your help (and the link). I am not familar with
        implementing
        FTP through PHP. It's mainly PHP with HTML forms. The PHP app runs on
        a
        Linux box (hopefully this does not matter) and I believe it also has
        ftp access. At this point, there will only be one computer that the
        PHP application will need to automatically load
        the TIF image. The file will be saved in a directory called xrays off
        of the C:\
        drive.

        Steve


        Comment

        • Aerik

          #5
          Re: automated upload with PHP

          On Mar 29, 8:29 pm, "Steve Poe" <steve....@gmai l.comwrote:
          sure, you can script on the client using what is called active
          scripting.
          its nice and familiar, so you would either
          1) have your script one once per day and upload any images not already
          uploaded from a set of folders
          2) configure explorer so you can right click and select upload image,
          your php script would be run in the bvackground with argument such as
          c:\path\to\php -r "%1"
          and it would do the rest.
          Why not use FTP if you are scripting this, as it will be nice and
          robust and can interact is a predicatable way with your fileserver -
          providing it can have an ftp serve running on it, like filezilla
          server.
          >
          oops I should have added, that if you have a few computers you need to
          install this on you could use NSIS (Nullsoft Scriptable Install
          System)http://nsis.sourceforge.net/Main_Pagetowrap up everything
          including the script that makes the right click functionality between
          tiffs and the php script, and distribute that.
          >
          Thanks for your help (and the link). I am not familar with
          implementing
          FTP through PHP. It's mainly PHP with HTML forms. The PHP app runs on
          a
          Linux box (hopefully this does not matter) and I believe it also has
          ftp access. At this point, there will only be one computer that the
          PHP application will need to automatically load
          the TIF image. The file will be saved in a directory called xrays off
          of the C:\
          drive.
          >
          Steve
          Hi Steve -
          Would it suit your requirement to hard code the path into the file
          upload box? The user still has to click "upload" but will not have to
          find the file each time.

          Aerik

          Comment

          • shimmyshack

            #6
            Re: automated upload with PHP

            On 30 Mar, 04:49, "Aerik" <asyl...@gmail. comwrote:
            On Mar 29, 8:29 pm, "Steve Poe" <steve....@gmai l.comwrote:
            >
            >
            >
            sure, you can script on the client using what is called active
            scripting.
            its nice and familiar, so you would either
            1) have your script one once per day and upload any images not already
            uploaded from a set of folders
            2) configure explorer so you can right click and select upload image,
            your php script would be run in the bvackground with argument such as
            c:\path\to\php -r "%1"
            and it would do the rest.
            Why not use FTP if you are scripting this, as it will be nice and
            robust and can interact is a predicatable way with your fileserver -
            providing it can have an ftp serve running on it, like filezilla
            server.
            >
            oops I should have added, that if you have a few computers you need to
            install this on you could use NSIS (Nullsoft Scriptable Install
            System)http://nsis.sourceforge.net/Main_Pagetowrapup everything
            including the script that makes the right click functionality between
            tiffs and the php script, and distribute that.
            >
            Thanks for your help (and the link). I am not familar with
            implementing
            FTP through PHP. It's mainly PHP with HTML forms. The PHP app runs on
            a
            Linux box (hopefully this does not matter) and I believe it also has
            ftp access. At this point, there will only be one computer that the
            PHP application will need to automatically load
            the TIF image. The file will be saved in a directory called xrays off
            of the C:\
            drive.
            >
            Steve
            >
            Hi Steve -
            Would it suit your requirement to hard code the path into the file
            upload box? The user still has to click "upload" but will not have to
            find the file each time.
            >
            Aerik


            active scripting is slightly different, it will run on the windows box
            where the tiffs are. php on the linux server isnt used at all. I
            thought you question was really about "automatic form submission" but
            this isnt allowed for security, so you have to program on the client
            computer itself. You can do this in any language of course, and
            because you seemed familiar with php, I just thought why not use php
            on the client too.
            For instance, my desktop here does a whole load of things at night,
            all using php. It scans direcories and uploads files to an ftp server,
            backs stuff up, copies files, and logs the results.

            What I would do is
            a) download and use a file/folder watcher like log monitor
            Freeware Orphans, The Lost Freeware - is a page where we keep the freeware that for one reason or another are no longer available on the World Wide Web. Freeware without author site.

            b) set it to automatically run a program (like copy blah to network
            drive blah) which uploads the changes
            c) write a small program that takes a path and filename and uploads it
            to the linux machine over ftp, or if you script using c#, you can just
            copy the file there using a mapped drive and samba.

            You dont need your users to interact with this process. It is done
            automatically. If the images need to get to the file server in real
            time, then you can use the watcher, otherwise you can run cronw 2
            (sourceforge) to sweep them all there at night.

            The reason I keep steering away from http uploads is because they tend
            not to be as robust as ftp. FTP can support resume, and other nice
            features like compression, (if your code does). You can though script
            an automatic form upload using c# or php or whatever, which is just a
            script - rather than one that runs in a browser. If you like c#
            or .NET check out codeproject for more.



            Comment

            • Steve Poe

              #7
              Re: automated upload with PHP

              On Mar 29, 8:49 pm, "Aerik" <asyl...@gmail. comwrote:
              On Mar 29, 8:29 pm, "Steve Poe" <steve....@gmai l.comwrote:
              >
              >
              >
              sure, you can script on the client using what is called active
              scripting.
              its nice and familiar, so you would either
              1) have your script one once per day and upload any images not already
              uploaded from a set of folders
              2) configure explorer so you can right click and select upload image,
              your php script would be run in the bvackground with argument such as
              c:\path\to\php -r "%1"
              and it would do the rest.
              Why not use FTP if you are scripting this, as it will be nice and
              robust and can interact is a predicatable way with your fileserver -
              providing it can have an ftp serve running on it, like filezilla
              server.
              >
              oops I should have added, that if you have a few computers you need to
              install this on you could use NSIS (Nullsoft Scriptable Install
              System)http://nsis.sourceforge.net/Main_Pagetowrapup everything
              including the script that makes the right click functionality between
              tiffs and the php script, and distribute that.
              >
              Thanks for your help (and the link). I am not familar with
              implementing
              FTP through PHP. It's mainly PHP with HTML forms. The PHP app runs on
              a
              Linux box (hopefully this does not matter) and I believe it also has
              ftp access. At this point, there will only be one computer that the
              PHP application will need to automatically load
              the TIF image. The file will be saved in a directory called xrays off
              of the C:\
              drive.
              >
              Steve
              >
              Hi Steve -
              Would it suit your requirement to hard code the path into the file
              upload box? The user still has to click "upload" but will not have to
              find the file each time.
              >
              Aerik
              Aerik,

              Hard-coding would solve this since the file name would be
              the same each time, I could change the name of the
              button "process image" instead of upload but it would still
              grab the image locally. How would you hard-code the location?

              In my example, the xray will be stored in c:\xrays_images and the file
              will be called xray.tif.

              Thanks for the feedback.

              Steve

              Comment

              • Steve Poe

                #8
                Re: automated upload with PHP

                On Mar 30, 1:37 am, "shimmyshac k" <matt.fa...@gma il.comwrote:
                On 30 Mar, 04:49, "Aerik" <asyl...@gmail. comwrote:
                >
                >
                >
                On Mar 29, 8:29 pm, "Steve Poe" <steve....@gmai l.comwrote:
                >
                sure, you can script on the client using what is called active
                scripting.
                its nice and familiar, so you would either
                1) have your script one once per day and upload any images not already
                uploaded from a set of folders
                2) configure explorer so you can right click and select upload image,
                your php script would be run in the bvackground with argument such as
                c:\path\to\php -r "%1"
                and it would do the rest.
                Why not use FTP if you are scripting this, as it will be nice and
                robust and can interact is a predicatable way with your fileserver -
                providing it can have an ftp serve running on it, like filezilla
                server.
                >
                oops I should have added, that if you have a few computers you need to
                install this on you could use NSIS (Nullsoft Scriptable Install
                System)http://nsis.sourceforge.net/Main_Pagetowrapupeverything
                including the script that makes the right click functionality between
                tiffs and the php script, and distribute that.
                >
                Thanks for your help (and the link). I am not familar with
                implementing
                FTP through PHP. It's mainly PHP with HTML forms. The PHP app runs on
                a
                Linux box (hopefully this does not matter) and I believe it also has
                ftp access. At this point, there will only be one computer that the
                PHP application will need to automatically load
                the TIF image. The file will be saved in a directory called xrays off
                of the C:\
                drive.
                >
                Steve
                >
                Hi Steve -
                Would it suit your requirement to hard code the path into the file
                upload box? The user still has to click "upload" but will not have to
                find the file each time.
                >
                Aerik
                >
                active scripting is slightly different, it will run on the windows box
                where the tiffs are. php on the linux server isnt used at all. I
                thought you question was really about "automatic form submission" but
                this isnt allowed for security, so you have to program on the client
                computer itself. You can do this in any language of course, and
                because you seemed familiar with php, I just thought why not use php
                on the client too.
                For instance, my desktop here does a whole load of things at night,
                all using php. It scans direcories and uploads files to an ftp server,
                backs stuff up, copies files, and logs the results.
                >
                What I would do is
                a) download and use a file/folder watcher like log monitorhttp://www.freeware-guide.com/download/index2.html
                b) set it to automatically run a program (like copy blah to network
                drive blah) which uploads the changes
                c) write a small program that takes a path and filename and uploads it
                to the linux machine over ftp, or if you script using c#, you can just
                copy the file there using a mapped drive and samba.
                >
                You dont need your users to interact with this process. It is done
                automatically. If the images need to get to the file server in real
                time, then you can use the watcher, otherwise you can run cronw 2
                (sourceforge) to sweep them all there at night.
                >
                The reason I keep steering away from http uploads is because they tend
                not to be as robust as ftp. FTP can support resume, and other nice
                features like compression, (if your code does). You can though script
                an automatic form upload using c# or php or whatever, which is just a
                script - rather than one that runs in a browser. If you like c#
                or .NET check out codeproject for more
                Thanks. I am not ready for C# yet (but, I've started reading about
                Mono). While I am not new to PHP, I humblely admit my coding skills
                are novice-like. I program enough to fix the program for the first-
                stage before my boss has me on some other I.T-related project.

                Thanks again.

                Steve


                Comment

                • shimmyshack

                  #9
                  Re: automated upload with PHP

                  On Mar 30, 7:50 pm, "Steve Poe" <steve....@gmai l.comwrote:
                  On Mar 29, 8:49 pm, "Aerik" <asyl...@gmail. comwrote:
                  >
                  >
                  >
                  On Mar 29, 8:29 pm, "Steve Poe" <steve....@gmai l.comwrote:
                  >
                  sure, you can script on the client using what is called active
                  scripting.
                  its nice and familiar, so you would either
                  1) have your script one once per day and upload any images not already
                  uploaded from a set of folders
                  2) configure explorer so you can right click and select upload image,
                  your php script would be run in the bvackground with argument such as
                  c:\path\to\php -r "%1"
                  and it would do the rest.
                  Why not use FTP if you are scripting this, as it will be nice and
                  robust and can interact is a predicatable way with your fileserver -
                  providing it can have an ftp serve running on it, like filezilla
                  server.
                  >
                  oops I should have added, that if you have a few computers you need to
                  install this on you could use NSIS (Nullsoft Scriptable Install
                  System)http://nsis.sourceforge.net/Main_Pagetowrapupeverything
                  including the script that makes the right click functionality between
                  tiffs and the php script, and distribute that.
                  >
                  Thanks for your help (and the link). I am not familar with
                  implementing
                  FTP through PHP. It's mainly PHP with HTML forms. The PHP app runs on
                  a
                  Linux box (hopefully this does not matter) and I believe it also has
                  ftp access. At this point, there will only be one computer that the
                  PHP application will need to automatically load
                  the TIF image. The file will be saved in a directory called xrays off
                  of the C:\
                  drive.
                  >
                  Steve
                  >
                  Hi Steve -
                  Would it suit your requirement to hard code the path into the file
                  upload box? The user still has to click "upload" but will not have to
                  find the file each time.
                  >
                  Aerik
                  >
                  Aerik,
                  >
                  Hard-coding would solve this since the file name would be
                  the same each time, I could change the name of the
                  button "process image" instead of upload but it would still
                  grab the image locally. How would you hard-code the location?
                  >
                  In my example, the xray will be stored in c:\xrays_images and the file
                  will be called xray.tif.
                  >
                  Thanks for the feedback.
                  >
                  Steve
                  file value attribute is read only.
                  Assuming you don't want to pay for an Active-X component, the only way
                  to do this programmaticall y is to alter the security settings of
                  Firefox, and make sure your users know to always use FF.
                  (you could force that using
                  <!--[if IE 5]>
                  <SCRIPT LANGUAGE="Javas cript">
                  alert("Use Firefox for this application");
                  </SCRIPT>
                  <P>Firefox is safer and just plain better!</P>
                  <![endif]-->


                  Now courtesy of http://www.captain.at/ajax-file-upload.php here is the
                  method:
                  type about:config and hit enter, type applets in the filter field,
                  then double click
                  signed.applets. codebase_princi pal_support so it is set to true.
                  (when you run the code ON THE PRODUCTION DOMAIN you see a pop up
                  allowing you to derestrict the security for this domain, when you are
                  happy check the remember my answer and allow to prevent your users
                  seeing the pop up)
                  You understand I wouldn't go this way at all, because while you own
                  and run the domain, this is JUST the kind of setting that someone who
                  uses XSS to gain entry to your intranet needs to completely won half
                  your file system!)

                  you've already got a php script that will take the upload but here it
                  is anyway reproduced from the site above: (it isn't particularly
                  secure)

                  <?php
                  print_r($_FILES );
                  ?>
                  <hr>
                  <?php
                  print_r($_POST) ;

                  //this will cause the file to appear when uploaded,
                  //in the same folder as this post.php php script
                  $fpath = dirname(__FILE_ _).'/';
                  //or use $fpath = '/path/to/upload/directory/';

                  // move (actually just rename) the temporary file to the real name
                  move_uploaded_f ile ( $_FILES{myfile} {tmp_name}, $fpath.$_FILES{ myfile}
                  {name} );

                  // convert the uploaded file back to binary

                  // javascript "escape" does not encode the plus sign "+", but
                  "urldecode"
                  // in PHP make a space " ". So replace any "+" in the file with %2B
                  first

                  $filename = $fpath.$_FILES{ myfile}{name};
                  $handle = fopen($filename , "r");
                  $contents = fread($handle, filesize($filen ame));
                  fclose($handle) ;

                  $contents = preg_replace("/\+/", "%2B", $contents);

                  $handle = fopen($filename , "w");
                  fwrite($handle, urldecode($cont ents));
                  fclose($handle) ;

                  ?>


                  and here is the html markup with script, some lines will be broken,
                  but go through it and check, and if you cant get it working email me,
                  and I'll send you the file.
                  Note I have changed a line at the top to get the filename
                  automatically, instead of from the form field, you now dont need the
                  file input field markup to be visible to the user of course (although
                  you might still need it to be present - I havent checked through the
                  js code)

                  as already said you will gt a warning, allow and then allow again, and
                  it should work, it posts to post.php by default, in the first instance
                  set it up to test using the file included in this post, I tested it
                  just now and it works just fine

                  <html>
                  <body>
                  <script>
                  var url = "post.php";
                  var binary;
                  var filename;
                  var mytext;

                  function upload() {
                  //here is how you could take the value from the form allowing your
                  users to browse first
                  //filename = ////document.getEle mentById('myfil e').value;

                  //but hey you want it to be AUTOMATIC, I was surprised it only had one
                  f in tif.
                  filename = 'C:\\xrays_imag es\\xray.tif';

                  mytext = document.getEle mentById('mytex t').value;
                  document.getEle mentById('ajaxb utton').disable d = true;

                  // request local file read permission
                  try {

                  netscape.securi ty.PrivilegeMan ager.enablePriv ilege("Universa lXPConnect");
                  } catch (e) {
                  alert("Permissi on to read file was denied.");
                  }

                  // open the local file
                  var file = Components.clas ses["@mozilla.o rg/file/local;
                  1"].createInstance (Components.int erfaces.nsILoca lFile);
                  file.initWithPa th( filename );
                  stream = Components.clas ses["@mozilla.o rg/network/file-input-stream;
                  1"].createInstance (Components.int erfaces.nsIFile InputStream);
                  stream.init(fil e, 0x01, 00004, null);
                  var bstream = Components.clas ses["@mozilla.o rg/network/buffered-
                  input-stream;1"].getService();
                  bstream.QueryIn terface(Compone nts.interfaces. nsIBufferedInpu tStream);
                  bstream.init(st ream, 1000);
                  bstream.QueryIn terface(Compone nts.interfaces. nsIInputStream) ;
                  binary = Components.clas ses["@mozilla.o rg/binaryinputstre am;
                  1"].createInstance (Components.int erfaces.nsIBina ryInputStream);
                  binary.setInput Stream (stream);

                  // start AJAX file upload in 1 second
                  window.setTimeo ut("ajax_upload ()", 1000);
                  }

                  function ajax_upload() {
                  // request more permissions
                  try {

                  netscape.securi ty.PrivilegeMan ager.enablePriv ilege("Universa lXPConnect");
                  } catch (e) {
                  alert("Permissi on to read file was denied.");
                  }

                  http_request = false;
                  http_request = new XMLHttpRequest( );
                  if (!http_request) {
                  alert('Cannot create XMLHTTP instance');
                  return false;
                  }

                  // prepare the MIME POST data
                  var boundaryString = 'capitano';
                  var boundary = '--' + boundaryString;
                  var requestbody = boundary + '\n'
                  + 'Content-Disposition: form-data; name="mytext"' + '\n'
                  + '\n'
                  + mytext + '\n'
                  + '\n'
                  + boundary + '\n'
                  + 'Content-Disposition: form-data; name="myfile"; filename="'
                  + filename + '"' + '\n'
                  + 'Content-Type: application/octet-stream' + '\n'
                  + '\n'
                  + escape(binary.r eadBytes(binary .available()))
                  + '\n'
                  + boundary;

                  document.getEle mentById('sizes pan').innerHTML = "requestbody.le ngth="
                  + requestbody.len gth;

                  // do the AJAX request
                  http_request.on readystatechang e = requestdone;
                  http_request.op en('POST', url, true);
                  http_request.se tRequestHeader( "Content-type", "multipart/form-data;
                  boundary=\"" + boundaryString + "\"");
                  http_request.se tRequestHeader( "Connection ", "close");
                  http_request.se tRequestHeader( "Content-length", requestbody.len gth);
                  http_request.se nd(requestbody) ;

                  }

                  function requestdone() {
                  if (http_request.r eadyState == 4) {
                  if (http_request.s tatus == 200) {
                  result = http_request.re sponseText;
                  document.getEle mentById('myspa n').innerHTML = result;
                  } else {
                  alert('There was a problem with the request.');
                  }
                  document.getEle mentById('ajaxb utton').disable d = false;
                  }
                  }

                  </script>

                  <form>
                  Text: <input type="text" id="mytext" name="mytext" size="40">
                  <br>
                  File: <input type="file" id="myfile" name="datafile" size="40"><br>
                  <input type="button" id="ajaxbutton " value="AJAX IT"
                  onclick="upload ();">
                  </form>

                  <div id="sizespan"> </div>
                  <hr>
                  <div id="myspan"></div>

                  </body>
                  </html>


                  NOW do you wish you had done the other thing!!

                  Comment

                  • Aerik

                    #10
                    Re: automated upload with PHP

                    >file value attribute is read only.

                    Oh crud. Sure is. Can't find any workarounds either... sorry about
                    that.

                    Comment

                    Working...