php - PHP 将文件写入 localhost 但不在 IIS 8 上
问题描述
请协助,我正在将文件写入我的applicationdir/uploads/
文件夹。通过在我的本地主机上写出文件时wamp64 host
,文件会完美生成。
但是,当我在我IIS 8.0 server
的 .
我正在使用File_Put_Contents
命令来创建文件。
我已经阅读了其他帖子,并且正如其他人所指出的那样,我已将我的applicationpool\MYAppPool
名字更改为类似于应用程序名称(无济于事)。我还允许iis_iusrs
写入目录的权限。
有什么想法吗?下面的PHP:
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['xml'] ) ){
$Counter = date("Y-m-d") . ' ' . Time();
$file = 'uploads/' . $Counter . ' - Export.xml';
$bytes = file_put_contents( $file, $_POST['xml'] );
exit( sprintf('%d bytes written to %s',$bytes,realpath($file) ) );
}
?>
截屏:
我看不出这会有什么不同,但这里是将 xml 数据传递给服务器的 javascript 代码。Javascript:
<script>
var template = [
'<?xml version="1.0"?>',
'<unattend xmlns="urn:schemas-microsoft-com:unattend">',
'<Data>',
' <SubmitBy><?SubmitBy?></SubmitBy>',
' <Level10><?Level10?></Level10>',
' <Level1><?Level1?></Level1>',
' <Level2><?Level2?></Level2>',
' <Level3><?Level3?></Level3>',
' <Level4><?Level4?></Level4>',
' <Title><?Title?></Title>',
' <Subject><?Subject?></Subject>',
' <Author><?Author?></Author>',
' <Keywords1><?Keywords1?></Keywords1>',
' <Keywords2><?Keywords2?></Keywords2>',
' <Destroy_Date><?Destroy_Date?></Destroy_Date>',
'</Data>',
'</unattend>'
].join('\r\n');
const ajax=function( params ){
with( new XMLHttpRequest() ){
onreadystatechange=function(e){
if( this.status==200 && this.readyState==4 ){
alert( this.response )
}
}
open( 'POST', location.href, true );
setRequestHeader('Content-Type','application/x-www-form-urlencoded');
send( params );
}
}
document.addEventListener('DOMContentLoaded', ()=>{
document.querySelector('input[ type="button" ]').addEventListener('click', e=>{
let vars={};
Array.prototype.slice.call( document.querySelectorAll('form > input[ type="text" ]') ).forEach( field =>{
vars[ field.name ]=field.value
});
Array.prototype.slice.call( document.querySelectorAll('select') ).forEach( field =>{
vars[ field.name ]=field.value
});
Array.prototype.slice.call( document.querySelectorAll('form > input[ type="date" ]') ).forEach( field =>{
vars[ field.name ]=field.value
});
let xml=template.replace(/<\?(\w+)\?>/ig, (match,name)=>{
return vars[name];
});
ajax.call( this, 'xml='+xml);
})
});
</script>
解决方案
推荐阅读
- python - BeautifulSoup:“类型错误/属性错误:'NoneType'”
- python - Django 检查文件并添加到数据库
- sql - 如何在基于 webpack-react-node 的网站中处理非常大的数据(100000 个 javascript 对象)?
- javascript - jQuery正则表达式删除不符合要求的数字
- html - 如何为多个类赋予相同的样式
- python - 如何查找包裹是否在包裹内?
- reactjs - 反应幻灯片问题
- visual-studio-code - 如何在 Vscode 中使用 Eslint 和 Prettier 更改缩进空间?
- c++ - 如何使用向量组合桶
- python - 带有异步等待变量的 pyzmq REQ/REP