Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript node.js将字符串转换为要上载到Web服务器的文件_Javascript_Html_Node.js_File Upload_Ftp - Fatal编程技术网

Javascript node.js将字符串转换为要上载到Web服务器的文件

Javascript node.js将字符串转换为要上载到Web服务器的文件,javascript,html,node.js,file-upload,ftp,Javascript,Html,Node.js,File Upload,Ftp,假设我有一个使用定义的变量动态创建的字符串。例如: <html> <head> .... blah blah blah .... </head> <body> <h1>Clan Name</h1> </body> </html> .... 胡说八道。。。。 族名 该字符串将存储为“htmlOutput”,然后我需要使用变量作为文件名将该字符串上载到we

假设我有一个使用定义的变量动态创建的字符串。例如:

<html>
   <head>
   .... blah blah blah ....
   </head>

   <body>

    <h1>Clan Name</h1>

  </body>

</html>

.... 胡说八道。。。。
族名
该字符串将存储为“htmlOutput”,然后我需要使用变量作为文件名将该字符串上载到web服务器上的目录。例如,文件名可能是495731951.html

这是如何实现的

我已经看过jsftp,但是没有用于上传字符串值的内容。我不想在本地机器上为每个文件创建一个新文件,因为会有很多文件


谢谢大家!

我假设您可以访问该远程服务器。我建议不要使用FTP,而是编写一个简单的PHP脚本来处理POST请求并保存文件

// save.php
$html = isset($_POST['content']) ? $_POST['content'] : '';
if($html !== '') {
  $file = 'file.txt';
  file_put_contents($file, $content);
}
我之所以建议使用PHP,是因为我想它在那里是受支持的。我再次假设该服务器上没有Node.js

一旦有了这样的文件(
save.php
),就可以将变量与模块一起发送


你假设的太多了,这不是一个有效的答案。了解事实,然后回答!是否还需要其他东西来检查是否已经有一个文件名为made>嗯,Shivam Paw,我想是的。您可能需要检查该文件是否存在。您可以始终创建本地文件,然后在处理完这些文件后将其删除。
request.post('http://service.com/save.php', {
  form: {
    content: htmlOutput
  }
});