File name change on windows server hangs 5.0.1

OEMR 5.0.1 Windows R2012 PHP 7.1.9 Apache 2.4.27 MySQL 5.7.19

We can upload a file to the windows server.
When trying to change the name of the file, the system just hangs and causes the server to crash.

I have tested this on two different windows server. This does not occur on the demo server which is Linux based.

Log file error comes in the form of a warning but it is a hard error

 [07-May-2018 22:45:51 America/Cayman] PHP Warning:  fopen(C:/emr_wamp/www/openemr/sites/default/documents//): failed to open stream: No such file or directory in C:\emr_wamp\www\openemr\controllers\C_Document.class.php on line 634
 [07-May-2018 22:45:51 America/Cayman] PHP Warning:  fpassthru() expects parameter 1 to be resource, boolean given in C:\emr_wamp\www\openemr\controllers\C_Document.class.php on line 656

I tried putting back the previous version of the C_Document.class.php file and the same thing happens. So the error is further up the tree.
@robert.down @MatthewVita @brady.miller @visolveemr
Since there is no owner in the file, I’m writing you four.

Spent half the night work on this and it is still doing the same thing. I can’t figure out where the code is going wrong. In testing I was dumping the variables to see what I was getting in each. The last variable I tested was $as_file. It is empty.

Any recent updates to anything in the infrastructure - a windows patch, mysql change, PHP update, anything?

This one will be tough for me to replicate because I don’t have a license for R2012 - if you have a spare license around and would be ok with me using it to spin up a VM to test this on let me know, I’ll make sure you’ve got my secure email.

These are on AWS servers. I can setup an AWS instance for you if you don’t have an ASW account.

There is nothing that I know of changed about the server. It does not receive automatic updates. The other machine is a Windows 7 box.

I just tried it on a clean install of windows and OEMR and it does the same thing. If you have a secure mailbox, I can send you credentials to log into one of my windows boxes.

I have just proven it is true that when the button is clicked the $url is incorrect.

The $url is dropping the pid folder name.

fopen(C:/emr_wamp/www/openemr/sites/default/documents//):

So, that is the cause of the failure. Now, need to figure out what is causing the folder name to be blank at line 634.

I’ve got an account, seems like you’re on track though. If you are still stuck let me know, I’ll spin up an instance

I am going to talk this out because it will help me to document what I see and try to figure out what smarty is doing or not doing.

I went back to the form to see if on submit the right information is being passed to the controller. And it is according to this below. The PID and document id are being passed to the document class. Now, have to figure out where is it getting lost.

<form method="post" name="document_update" action="/openemr/controller.php?document&amp;update&amp;patient_id=28407&amp;document_id=132917&amp;process=true" onsubmit="return top.restoreSession()">
            <div>
                <div style="float:left">
                    <b>Update</b>&nbsp;
                </div>
                <div style="float:none">
                    <a href="javascript:;" onclick="document.forms['document_update'].submit();">(<span>submit)</span></a>
                </div>
            </div>
            <div>
                Rename:
                <input type="text" size="20" name="docname" id="docname" value="somefile.jpg">
          	</div>
            <div>
                Date:
                <input type="text" size="10" class="datepicker" name="docdate" id="docdate" value="2018-05-07" title="yyyy-mm-dd document date">
                <select name="issue_id"><option value="0">-- Select Issue --</option></select>
            </div>
            </form>

I added this line to the file to fix the issue instead of trying to figure out what is causing it to drop the $patient_id.

    if (strpos($url, '//')){
           
         $url2 = substr(($url), 0, -1);

         file_put_contents("line634.txt", $url . " - " . $url2 . $patient_id ."/");

         $url = $url2 . $patient_id ."/";

    }

Now I need to know how to get the right document.

Didn’t really fix anything.

[08-May-2018 18:05:32 America/Cayman] PHP Warning:  fopen(C:/emr_wamp/www/openemr/sites/default/documents/15616/): failed to open stream: No such file or directory in C:\emr_wamp\www\openemr\controllers\C_Document.class.php on line 643
[08-May-2018 18:05:32 America/Cayman] PHP Warning:  fpassthru() expects parameter 1 to be resource, boolean given in C:\emr_wamp\www\openemr\controllers\C_Document.class.php on line 665

notice the two slashes at end of url! kind of a no no isn’t it?
edit meant file path

Not sure it matters, but it technically shouldn’t be there

Ok, so I will remove one slash.

    if (strpos($url, '//')){
           
         $url2 = substr(($url), 0, -1);
    }

Check for two slashes and if they are there remove one.

But why are there 2 slashes to begin with?

It does not matter if there are one or two slashes. The system still hangs either way. I just tried it with one slash and the system hung.

Seems I’ve seen this issue before with url formatting in Documents. Just can’t put finger on but will look see.

Here is a hint that may help. Check out C_Document.class.php at line L1412 where DIRECTORY_SEPARATOR = backward slash(windows) while the file path is saved as a forward slash. Okay for url’s but not to parse parts in file path…

1 Like