简体   繁体   English

WinSCP刷新PHP中的代码库? 使用XMLHttpRequest对文件进行加密后如何刷新服务器

[英]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. 我正在使用上述XMLHttpRequest将文件发送到服务器-文件大小为200KB-400KB-该文件本质上是即时在服务器上-但是,要立即查看该文件,我使用了WinSCP ftp软件刷新功能。

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? 我需要另一个PHP脚本来尽快访问这些上载的文件并进行处理? Right now the files are not visible to my php scirpt unless I manually refresh (using the WinSCP refresh feature). 现在,除非我手动刷新(使用WinSCP刷新功能),否则文件对我的php脚本不可见。

Update: I have 2 computers at 2 different locations. 更新:我在2个不同的位置有2台计算机。 Both computers sending files using the upload.php script. 两台计算机都使用upload.php脚本发送文件。 Only after both uploads are completed, I can run the second php script. 只有两个上传都完成后,我才能运行第二个php脚本。 This is what preventing me from including the second php script in the upload.php. 这就是阻止我将第二个PHP脚本包含在upload.php中的原因。 How can I resolve this without using WinSCP refresh feature? 不使用WinSCP刷新功能如何解决此问题? Below is the upload.php code: 以下是upload.php代码:

$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);"? 如果WinSCP具有刷新服务器的功能,则可以在上面的upload.php中或“ 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? 更新2:我在上面的脚本中添加了以下行,希望它可以刷新-它没有刷新?

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. 当您请求./upload.php ,可以在该PHP脚本中处理上载的文件。

if you're planning to refresh those uploaded files in your WinSCP ftp software, then PHP script would not help you refresh it automatically. 如果您打算在WinSCP ftp软件中刷新那些上传的文件,则PHP脚本不会帮助您自动刷新它。 You need to manually refresh. 您需要手动刷新。 Because the ftp tools doesn't have socket feature to update the files list automatically. 因为ftp工具没有套接字功能来自动更新文件列表。 you need to refresh them manually. 您需要手动刷新它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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