简体   繁体   中英

WinSCP refresh codebase in PHP? How to refresh the server after seding a file using XMLHttpRequest

function upload(blobOrFile) {
  var xhr = new XMLHttpRequest();
  xhr.open('POST', './upload.php', true);
  xhr.onload = function(e) {};
  // Listen to the upload progress.
  var progressBar = document.querySelector('progress');
  xhr.upload.onprogress = function(e) {
    if (e.lengthComputable) {
      progressBar.value = (e.loaded / e.total) * 100;
      progressBar.textContent = progressBar.value; // Fallback for unsupported browsers.
    }
  };

  xhr.send(blobOrFile);
}

I am using the above XMLHttpRequest to send a file to the server - the file size is 200KB - 400KB - the file is essentially on the server instantly - however, to see the file instantly, I have used the WinSCP ftp software refresh feature.

Is there a script or another way to do this automatically? I need another php script to access these uploaded files asap and process them? Right now the files are not visible to my php scirpt unless I manually refresh (using the WinSCP refresh feature).

Update: I have 2 computers at 2 different locations. Both computers sending files using the upload.php script. Only after both uploads are completed, I can run the second php script. This is what preventing me from including the second php script in the upload.php. How can I resolve this without using WinSCP refresh feature? Below is the upload.php code:

$fp = fopen( 'savedfile.wav', 'wb' );
fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );
fclose( $fp );

If WinSCP has a feature to refresh the server, then there can a codebase that can be included in the above upload.php or right after the "xhr.open('POST', './upload.php', true);"? What is it? Update 2: I added the following line to the above script hoping it might refreh - it did not refresh?

exec("touch -a './path/' . $filename");
  xhr.open('POST', './upload.php', true);

When you're making a request to ./upload.php , you can process the uploaded file in that PHP script.

if you're planning to refresh those uploaded files in your WinSCP ftp software, then PHP script would not help you refresh it automatically. You need to manually refresh. Because the ftp tools doesn't have socket feature to update the files list automatically. you need to refresh them manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM